threepointone / react-state

localized react state component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-state

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.

props

  • initial
  • onChange: function
  • children: function

based on this thread

made this repo to use / test shallow rendering and whatnot. wish me luck.

(tests curently PASS.)

About

localized react state component


Languages

Language:JavaScript 100.0%