Skip to content
Middle44 views

[имя] что именно передаётся в `dispatch`? Что такое action и action creator?

Practice

Asked at

AI answer

In Redux, you pass an action to dispatch—usually a plain object with a required type field and, if needed, data (payload): dispatch({ type: 'user/loaded', payload: user }).

An action creator is a function that creates and returns an action, for example const userLoaded = user => ({ type: 'user/loaded', payload: user }). Pass its result to dispatch: dispatch(userLoaded(user)). With middleware such as redux-thunk, dispatch can also accept a function.