Last active
September 26, 2020 21:24
-
-
Save lushiyun/239f65dd925546bc19a1b8715833a5f7 to your computer and use it in GitHub Desktop.
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
// src/features/messages/messagesSlice.js | |
... // omitted imports | |
const messagesAdapter = createEntityAdapter() | |
const initialState = messagesAdapter.getInitialState({ | |
... | |
}) | |
... // omitted thunks | |
const messagesSlice = createSlice({ | |
name: 'messages', | |
initialState, | |
reducers: { | |
messageReceived(state, action) { | |
const data = action.payload.data | |
const message = { | |
id: data.id, | |
...data.attributes, | |
teamId: data.relationships.team.data.id, | |
userId: data.relationships.user.data.id, | |
} | |
messagesAdapter.addOne(state, message) | |
}, | |
}, | |
extraReducers: { | |
... | |
}, | |
}) | |
export const { messageReceived } = messagesSlice.actions | |
export default messagesSlice.reducer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment