Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Created June 4, 2020 03:48
Show Gist options
  • Save ericelliott/09efa2ef7d6aa7da7696f489c7326dd1 to your computer and use it in GitHub Desktop.
Save ericelliott/09efa2ef7d6aa7da7696f489c7326dd1 to your computer and use it in GitHub Desktop.
after-immer.js
import produce from 'immer';
const like = item => ({
type: like.type,
payload: item
});
like.type = 'user/like';
const initialState = {
name: 'Anonymous',
avatar: 'Anonymous',
email: '',
walletAddress: '',
likes: {}
};
// After immer
const reducer = produce((draft, { type, payload } = {}) => {
switch (type) {
case like.type: {
draft.likes[payload.id] = payload;
return;
}
default:
return draft;
}
}, initialState);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment