1.0.2 • Published 5 months ago

react-pine v1.0.2

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

Usage

Import

import ReactDOM from 'react-dom/client';
import App from './App';
import { Provider } from 'react-pine';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <Provider>
    <App></App>
  </Provider>
);

Define Store

import { createStore } from 'react-pine';

export const useStore = createStore('id', {
  states: {
    count: 0,
  },
  buildMoreActions: ({ count, setCount }) => {
    return {
      add: () => {
        setCount(1);
      },
    };
  },
  buildGetters: ({ count }) => {
    return {
      newCount: count + 1,
    };
  },
});

Use Store

function App() {
  const { count, add, setCount, newCount } = useStore();

  return (
    <>
      <div>{count}</div>
      <div>{newCount}</div>
      <button onClick={add}>add</button>
    </>
  );
}
1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago