reapex-plugin-immer

use immer for redux state


Keywords
reapex, redux, immer
License
MIT
Install
npm install reapex-plugin-immer@2.0.0

Documentation

Reapex immer plugin

import { App } from 'reapex'
import immer from 'reapex-plugin-immer'

const app = new App()

// 1. register the plugin
app.plugin(immer)

// 2. in mutations, we can expect the state it receives as an immer draft object
interface TodoState {
  todos: string[]
}

const initial: TodoState = {
  todos: [],
}

const TodoModel = app.model('todos', initial)

const [mutations] = TodoModel.mutations({
  add: (todo: string) => state => {
    // the state here is an immer draft
    state.todos.push(todo)
    return state
  },
})