Skip to content

Instantly share code, notes, and snippets.

@Rajatgms
Created August 6, 2020 02:41
Show Gist options
  • Save Rajatgms/383c4576c04f630d839ba799071a610b to your computer and use it in GitHub Desktop.
Save Rajatgms/383c4576c04f630d839ba799071a610b to your computer and use it in GitHub Desktop.
use Payload Creator
const todosSlice = createSlice({
name: 'cart',
initialState: [],
reducers: {
addItem: {
reducer: (state, action) => {
state.push(action.payload)
},
prepare: item => {
const id = nanoid()
return { payload: { id, ...item } }
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment