How to make a shared state between two react components?

前端 未结 5 499
盖世英雄少女心
盖世英雄少女心 2020-11-27 07:04

I have 2 react components that need to share a state, react-router shows component A, which takes some inputs and adds it to its state, after the state has been successfully

5条回答
  •  感情败类
    2020-11-27 07:12

    Either you can set up a parent child relationship then you can pass data to child components as props.

    Else, if you want to create interaction between 2 components which are not related to either(parent/child) you can either check out flux or even better redux.

    I would say you should go with redux.See Here why

提交回复
热议问题