I need to pass check box values to one child component to another child component, but parents are different and same grand parents using react js?
I pass value as props from one child component to parent component. But i think there is a correct solution for this. Please help
3
Answers
Bad way: Pass the value to parent -> grandparent -> other parent -> destination.
Good way: Use state manager like Redux or Context
Use state for that check box values in the grandparents component then pass them as props in the child hierarchy.
two child’s – 1.parent1 component(childs – 1.child1 component)
2.parent2 component(childs – 1.child2 component)
It depends.
How large is that data? If it’s a simple string and there’s no issue with storing it on the URL, use the query parameter as a single source of truth, but if it’s a bit larger or you don’t want to expose it to the URL, the React Context can be your answer.