score:2
Accepted answer
the only required property
of an action
is type
, every other property is arbitrary. as long as your reducer knows how to deal with it you can dispatch
pretty much anything (including components
).
dispatch({
type: 'my_action',
data: {
arr: [],
str: 'foo',
}
})
const reducer = (state = initialstate, action) =>{
switch(action.type){
case 'my_action' return {
...state,
myarr : action.data.arr
}
default : return state
}
}
Source: stackoverflow.com
Related Query
- Can I dispatch object rather than just strings?
- How can I close a Material UI Modal using an X icon rather than just by clicking outside the modal?
- What's the use of mapDispatchToProps when we can just use this.props.dispatch to dispatch action
- Does redux-form field value can hold object instead of just a string?
- react-native-google-places-autocomplete give it a value rather than just default (initial) value
- Why is React Router causing my components to re-mount, rather than just re-rendering?
- why add ref to child ref can only get a component instance rather than a DOM node?
- How to export custom modules as global across the project and import by just providing the name rather than path in js?
- Is there a way that we can trigger mouseover event on echarts library when hovering on any point of the series, rather than hover on a data point?
- How to pass an array of id's to delete using an endpoint rather than just one Id
- onMouseOver in React element selecting all elements rather than just single
- Javascript Object is pushing on both indexes rather than specific index
- How can I modify my webpack project to reference itself from a discreet location, rather than from a relative path?
- In ES6 with react, can I destructure an object just once for use in multiple methods?
- React/Material-UI: How can I map multiple tables from a JSON object with more than one array of data?
- Is it OK to use unique, stable functions (e.g. components) rather than strings as React keys?
- Function always performs action on last mapped object rather than the one i choose while in Modal
- TS RadioGroup returns type string on change handler rather than array of possible strings
- Does 'dispatch' have to be called 'dispatch' or can you just call a dispatch without labeling it?
- Can you use template strings as an object value?
- react-select to just include values in form, rather than value: '' and label: ''
- How to bind an object to an input tag than just a value with ReactJS?
- When can you use reactDOM in react/how can i make something appear on screen rather than in consoke?
- I just want to output the products in the dashboard, In which the quantity is less than 10. It is connected in the firestore. How can I improve this?
- My else part of add to cart functionality is also putting the new quantity in the cartItems array rather than just increasing quantity of Items
- React: How to update state for just one element, rather than batch update
- How can i extract more than one key from an Object and print the output
- Can I dispatch an action in reducer?
- How can I map through an object in ReactJS?
- How can I remove an attribute from a React component's state object
More Query from same tag
- How to render a full html in reactjs
- why the Button changing position onClick?
- "Internal Server Error" when refreshing page or typing URL manually when using React Router
- How to send requests from nginx & react container to a spring boot container?
- Using 'styled()' MUI utility with additional props (Typescript)
- Typescript error (2345) when pushing element to array of elements(React js)
- How to hook up React Dropzone & Redux form
- How to get input value onCut in ReactJS
- Making a stopwatch counter with user filled data and with PAUSE/RESUME and RESET functionality
- Best way for internationalization with Gatsby and Strapi
- type for material UI icons
- Material UI Dialog close dialog from inner component
- Type checking issues with Redux reducer
- How does npm start work? What all processes are happening in the background?
- Force new line on minified react build
- why leaflet map doesn't render on react app
- Proper way of passing asynchronous data in nextjs to pages
- React: setting state in container from within functional component
- Pie Chart not rendering React Chart.js
- React child component do not re-render on it state change
- Typescript/React - destructuring from this.state throws error
- Child React Component Will Not show on state change
- Updating state inside useCallback - React JS
- what will be best Approach for Redux-thunk Async Request to handle onSuccess and onError?
- .populate() returning empty array?
- Lodash debounce error: Uncaught TypeError: Expected a function
- nx React/Next.js shared type declaration file
- Bundler does not load automatically (No bundle URL present error)
- Getting react passed props & redux state at same time in component
- React: Bind number input to state (handle intermediate values)