In my project, I have an action creator that depends on the values that are in the application state in order to generate a new value or decide which action to send. My question is to know which way to do this. I thought of two ways. Access these values inside the action creator:
export const changePreviousPage = () => { return (dispatch, getState) => { let pagination = getState().appReducers.availability.pagination; let previousPage = pagination.actualPage != 1 ? pagination.actualPage - 1 : pagination.actualPage; dispatch({ type: types.CHANGE_PREVIOUS_PAGE, previousPage }); } };
Another option I thought was to pass the value from the component to the action creator:
In my component
class Pagination extends Component { ... handlePreviousPage() { const {pagination} = this.props; this.props.changePreviousPage(pagination); } ... }
In my action creator
export const changePreviousPage = pagination => { let previousPage = pagination.actualPage != 1 ? pagination.actualPage - 1 : pagination.actualPage; return{ type: types.CHANGE_PREVIOUS_PAGE, previousPage } };
What is the best way to solve it?
- / , (, , , , ).
, , store.dispatch. , store.dispatch, .
- , , . , let state = getState() , , ( - API, getState() ).
let state = getState()
, ( redux connect helper) , , .
, mapDispatchToProps (, , , handlePreviousPage) ( , , - , ).
Source: https://habr.com/ru/post/1648321/More articles:Amount of a separate invoice with a date (day) - sqlError trying to create database - Ecto - Phoenix - postgresqlRespond to internal development errors by hitting a catch () network request - fetchSpring merge configuration Application context not installed - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1648320/wordpress-move-inline-js-to-be-fired-after-deffered-jquery&usg=ALkJrhgnjUvAKSmBfYsNoV7GyPEryw2cUwsum properties of an object in an array of objects into a single Lodash object - javascriptThis operation is not supported in the environment in which this application is running. "location.protocol" must be http or https - facebookngIf контейнер разрывает асинхронный - angularA faster algorithm for matching maximum weight in a bipartite graph - algorithmHow do I send a notification using the Eddystone URL? - androidAll Articles