@rematch/immer v2.1.3
Rematch Immer
Immer plugin for Rematch. Provides immutable ability on immer library.
Install
npm install @rematch/immer
For @rematch/core@0.x use @rematch/immer@0.1.0
Setup
import immerPlugin from '@rematch/immer'
import { init } from '@rematch/core'
const immer = immerPlugin()
init({
plugins: [immer]
})
Usage
Use Immer plugin, reducer could be use mutable method to achieve immutable state. Like the example:
const todo = {
state: [{
todo: "Learn typescript",
done: true
}, {
todo: "Try immer",
done: false
}],
reducers: {
done(state) {
state.push({todo: "Tweet about it"})
state[1].done = true
return state
}
}
};
In Immer, reducers perform mutations to achieve the next immutable state. Keep in mind, Immer only supports change detection on plain objects and arrays, so primitive values like strings or numbers will always return a change. Like the example:
const count = {
state: 0,
reducers: {
add(state) {
state += 1
return state
}
}
};
I suggest to developers that reducers could return changed value all the time.
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago