How to use the storeon function in storeon

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 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' });

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