communication components react, mainly divided into the following cases
A parent-child assembly, The props father to son, the parent child callback pass
- Down transfer
Parent component subassembly to the traditional values, by
props
passing
Parent component to component grandchildren, great-grandchildren, and so have a direct or indirect relationships invoked components by value, or by
props
the layers passed on, but after this level will not find too manyprops
data sources.
- Passed up
Sub-assemblies to the parent component by value, by way of a callback function, parent component by first
props
passed to a function sub-assemblies, subassemblies, call this function, nature or throughprops
delivery.
Grandchildren, great-grandchildren component is passed up the layers above call.
Second, there is no communication component nesting relationship
- To find a common parent component, an intermediate component to a value transfer
- Event publish - subscribe model
The entire project to create a common Event object, the object's properties and methods can be invoked globally.
Three, redux, Mobx and other global state management library
Four, react16 new context API
We can get through context directly from the ancestor component values, without the need for transfer layers.
Similar new contextAPI with redux usage.
Reproduced in: https: //juejin.im/post/5d08b6746fb9a07f021a02fb