[Docs] `prepare` callback have incorrect arguments(should be wrapped in curly brackets)
ronycage opened this issue · 1 comments
ronycage commented
What docs page needs to be fixed?
- Section: Redux Essentials > Using redux data
- Page: Preparing Action Payloads, Adding Authors for Posts
What is the problem?
Incorrect arguments in prepare
callback
const postsSlice = createSlice({
name: 'posts',
initialState,
reducers: {
postAdded: {
reducer(state, action) {
state.push(action.payload)
},
prepare(title, content) {
return {
payload: {
id: nanoid(),
title,
content
}
}
}
}
// other reducers here
}
})
What should be changed to fix the problem?
prepare should be deconstructed like this prepare({title, content})
markerikson commented
Hi! The listed usage should be correct. Part of the point of a prepare()
callback is that it lets the action creator accept multiple individual arguments, instead of the default single argument.
See the usage a bit further down:
dispatch(postAdded(title, content))