0.1.1 • Published 4 years ago

@easy-peasy/react v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Actions Status

React Connector

npm install @easy-peasy/react
yarn add @easy-peasy/react

Basic Usage

Step 1 - Export an existing easy-peasy store

import store from 'some-pkg';

Step 2 - Wrap your application

import { StoreProvider } from '@easy-peasy/react';

function App() {
  return (
    <StoreProvider store={store}>
      <TodoList />
    </StoreProvider>
  );
}

Step 3 - Use the store

import { useStoreState, useStoreActions } from '@easy-peasy/react';

function TodoList() {
  const todos = useStoreState(state => state.todos.items)
  const add = useStoreActions(actions => actions.todos.add)
  return (
    <div>
      {todos.map((todo, idx) => <div key={idx}>{todo}</div>)}
      <AddTodo onAdd={add} />
    </div>
  )
}