react-context-decorator
v1.0.0
Published
a react context decorator, easier for react bind context.
Downloads
1
Readme
React Context Decorator 封装
使用
npm install 'react-context-decorator' --save
绑定 context
// 绑定context
import { ContextProvider } from 'react-context-decorator';
import ChildComponent from './ChildComponent';
import React, { Component } from 'react';
class Index extends Component {
render() {
const props = {
color: 'red',
name: 'context'
};
return (
<ContextProvider
{
...props
}
>
<ChildComponent />
</ContextProvider>
);
}
}
export default Index;
// 子组件注入context
import React, { Component } from 'react';
import { injectContext } from 'react-context-decorator';
@injectContext(['type', 'name'])
class ChildComponent extends Component {
render() {
const { type, name } = this.props;
return (
<div>
{name}
</div>
);
}
}
export default ChildComponent;