Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update object state #17

Open
will83 opened this issue May 28, 2020 · 0 comments
Open

Update object state #17

will83 opened this issue May 28, 2020 · 0 comments

Comments

@will83
Copy link

will83 commented May 28, 2020

I came from a standard useState hook and my code was working properly.
Now, I can't update my state (the custom_filters object) with the SetFilters method below

const initialState = { 
  custom_filters: {
    blue: false,
    green: false,
    pink: false
  }
}
const [filters, setFilters, deleteFilters] = useStore('custom_filters');

const CustomSwitch = (props) => {
  const paramId = props.id;
  const paramValue = filters[paramId];
  
  return(
    <Switch
      value={paramValue}
      onValueChange={value => {
        setFilters(prevState => ({ ...prevState, [paramId]: value }));
      }}
    />
  )
}

{...}
<CustomSwitch id="blue" />

This is working : setFilters({[paramId]: value }); but I need to keep all my items inside custom_filters.

There is something wrong with my code?
Thank you for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant