skip to Main Content

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


  1. Bad way: Pass the value to parent -> grandparent -> other parent -> destination.

    Good way: Use state manager like Redux or Context

    Login or Signup to reply.
  2. Use state for that check box values in the grandparents component then pass them as props in the child hierarchy.

    1. grandparents component state passes to parent as props then that props pass from parent to its children
      two child’s – 1.parent1 component(childs – 1.child1 component)
      2.parent2 component(childs – 1.child2 component)
    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search