Rcf is a react component, it uses a clear and simple way to manage your state: Do not use "this.state" and "this.setState", just use store, which is a plain object.
Put your component in Rcf and Rcf allows it to get store by "this.props.*" and set store by "this.props.set".When you call 'set' function,it will change the value of store, then all of the Rcf component using this store will be re rendered.
npm install rcf
class A extends Component {
handleClick = () => {
this.props.set({
a: this.props.a - 1,
});
}
render() {
return <div>
A:
{this.props.a}
<button onClick={this.handleClick}>
click
</button>
</div>;
}
}
class B extends Component {
render() {
return <div>
B:
{this.props.a}
</div>;
}
}
const store = {a: 1};
ReactDOM.render(<div>
<Rcf store={store}>
<A />
<B />
</Rcf>
<Rcf store={store}>
<B />
</Rcf>
</div>,
mountDom);
http://flutejs.github.io/rcf/examples/example-a.html
handleClick = () => { this.props.set({ a: this.props.a - 1, }); } render() { return
A:
{this.props.a}
<button onClick={this.handleClick}>
click
</button>
</div>;
}
}
class B extends Component { render() { return
B:
{this.props.a}
</div>;
}
}
const store = {a: 1};
ReactDOM.render(
,name | type | description |
---|---|---|
store | object | plain object |
tag | string | object | default: 'div', the root element
When the number of children is greater than 1, set root element to tag |
set | string | default: 'set', the name of set function.
If you don't want to call "this.props.set", you can set "set" to what you want, then you can use "this.props.*"
|