reduxjs / redux

A JS library for predictable global state management

Home Page:https://redux.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Docs] `prepare` callback have incorrect arguments(should be wrapped in curly brackets)

ronycage opened this issue · comments

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})

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))