Why
The purpose of this project is to try Rematch, which is a state management framework based on Redux. It feels a little similar to Vuex and is much easier to use than Redux. The core is Model, Dispatch and reducers. Better to understand than Redux and use Redux Devtools and Reactotron without configuration.
First step
Define your Model and initialize it with the init method.
// todos.js export const todos = { state: [], reducers: { addTodo () {... }, removeTodo () {... }, editTodo () {... } }, effects: { async loadToads () {... } } } // index.js import { init } from '@rematch/core' import { todos } from 'path/todos' const store = init({ models: { todos } })Copy the code
Second step
Give the App a store Provider, call the Dispatch method in the Container component, and have your defined Reducers respond to the Action to update the state.
; <Provider store={store}> <App /> </Provider> // todoInput import { dispatch } from '@rematch/core' Dispatch.todos.addtodo (newTodo) // Dispatch ({type: 'todos/removeTodo', todoId}) // �You done!Copy the code
Compare
Live Demo
Usage
git clone [email protected]:xrr2016/rematch-todos.git
cd rematch-todos && yarn
yarn build
serve -s buildCopy the code
Reference
Redux Rematch React-redux
License
MIT