/louis-xiv

React state as a component

Primary LanguageJavaScriptMIT LicenseMIT

The state? I am the state.

— Louis XIV


🛑 Deprecated


Usage

npm version

Install:

$ yarn add louis-xiv

Use:

import React from "react";
import { render } from "react-dom";
import State from "louis-xiv";

const App = () => (
  <State
    init={{ counter: 0 }}
    map={(state, setState, deferredSetState) => ({
      ...state,
      increment: () => setState(prev => ({ counter: prev.counter + 1 }))
    })}
  >
    {({ counter, increment }, setState, deferredSetState) => (
      <div>
        <h1>{counter}</h1>
        <button onClick={increment}>+</button>
      </div>
    )}
  </State>
);

render(<App />, document.getElementById("root"));

Similar

License

Released under MIT license.