context的使用
const {Provider, Consumer} = React.createContext(defaultValue);
<Provider value={/*共享的数据*/}>
/*里面可以渲染对应的内容*/
</Provider>
用法1:
<Consumer> {value => /*根据上下文 进行渲染相应内容*/} </Consumer>
用法2:类上绑定静态属性。
static contextValue =
Consumer
用法3:函数组件 + hooks (useContext)
constcontextValue =
useContext(
Consumer
)