i am new to JS. And I wondered what is more prefered way for updating data in children components. Is that better to use hooks or redux? Let say i have a parent component with 3 child components.
<Parent>
<ChildA/>
<ChildB/>
<ChildC/>
</Parent>
And i have a need to update something in ChildA and ChildB and pass it to ChildC
What would the best way to do it ?
Shall i use hooks like this?
[childAValue, setChildAValue] = useState([])
[childBValue, setChildBValue] = useState([])
<ChildA onChildChanged={(e) => {
setChildAValue(e)
}}
/>
<ChildB onChildChanged={(e) => {
setChildBValue(e)
}}
/>
<ChildC childAValue={childAValue} setChildBValue={setChildBValue} />
Or it's better to use redux ? Because with using hooks i may have a lot of rerendering if there are 3-4 components or more. But on the other hand Redux will be just overloaded if i will use it for every possible component Which way do you prefer more and why? This question also refears to modals also when you need to pass value from modals to suibling component/s.
here you have multiple child components, you need to pass down functions to change them in all of them, redux can be used here and it will remove the hassle pass down props to each of the components. Redux is industry standard and is being used in large web projects, where you need to manage a global state to be present and accessible in all of the components/modules, for example Authentication state, for your question simply passing down as props also works so there is no need to complicate things further.