How to use storeon - 4 common examples

To help you get started, we’ve selected a few storeon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github storeon / localstorage / test / demo / index.js View on Github external
function App () {
  return h(Fragment, null,
    h('div', null, 'After refresh the page the state should be same'),
    h(Tracker1),
    h('div', { className: 'buttons' },
      h(Button1),
      h(ButtonClear)
    )
  )
}

let store = createStore([counter, logger, persistState(), devtools()])

render(
  h(StoreContext.Provider, { value: store }, h(App)),
  document.querySelector('main')
)
github dai-shi / will-this-react-global-state-work-in-concurrent-mode / src / storeon / index.js View on Github external
import {
  syncBlock,
  useRegisterIncrementDispatcher,
  initialState,
  reducer,
  ids,
  useCheckTearing,
  shallowEqual,
} from '../common';

const counter = (store) => {
  store.on('@init', () => initialState);
  store.on('dispatch', reducer);
};

const store = createStore([counter]);

const Counter = React.memo(() => {
  const { count } = useStoreon('count');
  syncBlock();
  return <div>{count}</div>;
}, shallowEqual);

const Main = () =&gt; {
  const { count, dispatch } = useStoreon('count');
  useCheckTearing();
  useRegisterIncrementDispatcher(React.useCallback(() =&gt; {
    dispatch('dispatch', { type: 'increment' });
  }, [dispatch]));
  const [localCount, localIncrement] = React.useReducer((c) =&gt; c + 1, 0);
  const normalIncrement = () =&gt; {
    dispatch('dispatch', { type: 'increment' });
github kidqueb / preact-polka-ssr / src / client / pages / Foods.js View on Github external
const Foods = ({ title }) =&gt; {
  const [clicks, setClicks] = useState(0)
  const { dispatch, foods = [] } = useStoreon('foods')

  return (
    <div>
      <h1>{ title }</h1>
      
      <div>
        {foods.list.map(food =&gt; <p>{food}</p>)}
      </div>

      <p>{clicks}</p>
      <p>
        <button> setClicks(clicks + 1)}&gt;Add</button>
      </p>
    </div>
  )
}
github dai-shi / will-this-react-global-state-work-in-concurrent-mode / src / storeon / index.js View on Github external
const Counter = React.memo(() =&gt; {
  const { count } = useStoreon('count');
  syncBlock();
  return <div>{count}</div>;
}, shallowEqual);

storeon

Tiny (180 bytes) event-based Redux-like state manager for React and Preact

MIT
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis