react-patty
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

React Patty

A tiny React state abstraction based on common patterns found in React applications.

Guiding principles:

  • Vanilla React: States should live in React's useState / useReducer. No external stores allowed.
  • No bad patterns: No skipping useEffect / useCallback / useMemo dependencies.
  • DevX focused: Simple + typed APIs, devtools integration.

‼️ Forward compatibility with future React features is the top priority.

Preview

Counter

import {createState} from 'react-patty/sync';

const Counter = createState(0, (prev, action) => {
  switch (action.type) {
    case 'INCREMENT':
      return prev + 1;
    case 'DECREMENT':
      return prev - 1;
    default:
      return prev;
  }
});

reactRoot.render(
  <Counter.Provider>
    <App />
  </Counter.Provider>
);

import {useValue, useDispatch} from 'react-patty';

function useCounter() {
  const dispatch = useDispatch(Counter);
  return {
    value: useValue(Counter),
    increment: () => dispatch({type: 'INCREMENT'}),
    decrement: () => dispatch({type: 'DECREMENT'}),
  };
}

Readme

Keywords

none

Package Sidebar

Install

npm i react-patty

Weekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

15.8 kB

Total Files

18

Last publish

Collaborators

  • raibima