Imperative State

Works with gstate .>= 0.1.3. Use new state.watch feature.

Declarative State Pattern is great but we still need a way to render ad-hoc state.

 const FormWithState = gstate(function(props){
     const state = props.state;
     const input1 = state.get("input1"); // all state.get inside the function will be reactive.
     const input2 = state.get("input2");

     return (
         <div>
             <p>Input1: {input1}</p>
             <p>Input2: {input2}</p>
             <input onChange={evt => state.set("input1", evt.target.value)}/>
             <input onChange={evt => state.set("input2", evt.target.value)}/>
         </div>
     )
 });

With imperative state, you're free to query any state by using state.get. If any state change match with those queries, the render will be triggered.

results matching ""

    No results matching ""