Created
June 4, 2020 03:46
-
-
Save ericelliott/1779bd9a166674ce26a76e2f37c6a491 to your computer and use it in GitHub Desktop.
before-immer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const like = item => ({ | |
type: like.type, | |
payload: item | |
}); | |
like.type = 'user/like'; | |
const initialState = { | |
name: 'Anonymous', | |
avatar: 'Anonymous', | |
email: '', | |
walletAddress: '', | |
likes: {} | |
}; | |
// Before immer | |
const reducer = (state = initialState, { type, payload } = {}) => { | |
switch (type) { | |
case like.type: { | |
return { | |
...state, | |
likes: { | |
...state.likes, | |
[payload.id]: payload | |
} | |
}; | |
} | |
default: | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment