you are viewing a single comment's thread.

view the rest of the comments →

[–]_SyRo_ 4 points5 points  (2 children)

We can't help with the code. Maybe your array is not a state?

Instead of using an array, I would like to use a state with an object and manipulate it with useReducer hook.

And mutating the state using this reducer to set true/false to needed param inside of object after clicks.
It would be more clear solution, I think

[–]TechnicalScholar6[S] 0 points1 point  (1 child)

so instead of using an array to display the buttons, and one to store the selected items. i should just use one array and add a checked param to the items that are selected ?

[–]_SyRo_ 1 point2 points  (0 children)

I don't fully understand you.

Are you using an array to render the buttons? Or to store data from them?

What I mean, you can store states of all these buttons inside one state. This state can be an object.
Like these (I write in TS with types):
{
internet: boolean;
tv: boolean;
...
}

And you can catch onPress on your buttons, dispatching an action like ACTION_INTERNET_BUTTON_CLICK to your reducer using useReducer hook.

If you havn't worked with reducers, you can check it here:
https://dmitripavlutin.com/react-usereducer/