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

1.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i react-pine

Weekly Downloads

0

Version

1.0.2

License

none

Unpacked Size

24.7 kB

Total Files

6

Last publish

Collaborators

  • 01_lct_01