react组件通信
父子组件
父组件通过this.props来向子组件传递方法和属性
子组件通过调用父组件传过来的方法,以入参的形式传递给父组件
兄弟组件
子传父后父传子
深层嵌套(contextApi
React.createContext返回一个带有Provider和Consumer的对象
const MyContext = React.createContext(默认值)
{value=> //渲染}
其他
event-bus redux
父组件通过this.props来向子组件传递方法和属性
子组件通过调用父组件传过来的方法,以入参的形式传递给父组件
子传父后父传子
React.createContext返回一个带有Provider和Consumer的对象
const MyContext = React.createContext(默认值)
{value=> //渲染}
event-bus redux