React多上下文
使用单个React组件管理多个上下文。
安装
npm install react-multi-context --save或
yarn add react-multi-context
测试
npm run test或
yarn test
利用
import createMultiContext from 'react-multi-context' ;
export const MyMultiContext = createMultiContext ( ) ;
通过在要创建上下文的任何位置导入并执行createMultiContext来创建上下文。 然后,根据需要导入该多上下文实例。
使用set设置上下文的值。 在上下文中更改键值对上的值将导致该键的所有获取器重新呈现。
使用get属性获取上下文的值。 使用此道具将通过传递上下文的相应值作为参数来执行children渲染道具。
例
// Parent.js
import createMultiContext from 'react-multi-context' ;
// Context to provide t
评论0
最新资源