localized state in React render functions.
npm install react-state --save
class Counter{
render(){
return <State initial={0}>{
(val, set) =>
<div onClick={() => set(val + 1)}>
clicked {val} times
</div>
}</State>;
}
}
React.render(<Counter/>, el); // just works.
// there's also a functional form to mask the reacty bits
class Counter{
render(){
return state({initial: 0}, (val, set) =>
<div onClick={() => set(val + 1)}>
clicked {val} times
</div>);
}
}
// that said, do remember that it's the reacty nature of
// that 'instance' that preserves it across renders, etc.
- initial
- onChange: function
children
: function
made this repo to use / test shallow rendering and whatnot. wish me luck.
(tests curently PASS.)