score:1
Accepted answer
add the payload to the front of the notifications and then slice off the rest (this way you also have latest notifications upfront.
case "add_notification":
return [{...action.payload}, ...(state.slice(0,2))];
}
Source: stackoverflow.com
Related Query
- ReactJS conditional dispatch reducer action
- reactjs axios interceptors how dispatch a logout action
- redux dispatch action and reducer with new state
- Dispatch not sending the action to the reducer
- Checkbox conditional rendering after action is performed - ReactJS
- Dispatch another action / call another reducer within a reducer
- react-redux: dispatch action from reducer
- How can I dispatch an action after every 5 min in reactjs
- How to get newly created post id generated from backend API after dispatch createPost action to a reducer
- Async function not waiting for returned data to dispatch action to reducer
- React-Redux action won't dispatch to the reducer
- reactJs redux: how to dispatch an action on a user event and link actions with the reducers and the store
- Try to connect Action with Reducer but get Error: Uncaught (in promise) TypeError: dispatch is not a function
- How to dispatch an action from reducer react-redux
- I am new to reactjs - looking to add some conditional class that come into action
- ReactJS - action to return a single item from reducer
- Redux - Reducer is not being called when I dispatch an action
- Disconnection between action dispatch and reducer
- Is it an anti pattern to dispatch actions from an action file that are subscribed to from a different reducer file?
- Can I dispatch an action in reducer?
- React/Redux - dispatch action on app load/init
- Simple Conditional Routing in Reactjs
- How to dispatch Redux action from stateless component when route is loaded?
- redux-thunk dispatch method fires undefined action
- React hooks: dispatch action from useEffect
- React Redux dispatch action after another action
- dispatch an action on componentDidMount (react/redux)
- Calling an action from a different reducer with React and redux
- How to dispatch an action when clicking on Link when using React-Router & Redux?
- What's the use of mapDispatchToProps when we can just use this.props.dispatch to dispatch action
More Query from same tag
- Testing a Material ui Select component without using testid
- css variable is not get applied to body tag
- Formik, Material UI Autocomplete and Firestore - where query to find the array parameter
- React - Shrink nav image on scroll down of the page
- return array of objects from props React JS
- React array of objects mapping with missing key causing TypeError crash
- How to store random numbers in muntiple items without repeating the last one javascript
- Node - Test if function call with 2 arguments using mocha/chai
- React best way to handle empty object before mount?
- Problem using JS ES6 promises in React - TypeError: Cannot read property 'then' of undefined
- Disable button when clicked in React JS
- Using React to make a simple messaging board. Do I have to set up a server, or can I store state locally?
- How to edit Array data in localstorage in React js
- how to remove the initial slash from bundle file path, publicPath, PUBLIC_URL in webpack with create-react-app?
- Testing window.name in Jest
- Objects are not valid as a React child when rendering an array of objects as children prop in storybook
- setState within componentDidUpdate comparing prev with current state not working to re-render page with new data, also getting infinite loop
- ReactJs bug to update array index in object
- store.dispatch is not a function
- Error resolving module specifier: react while doing dynamic import from API
- Have problem with boolean alternation in react,
- React Animation With GSAP
- CSS classnames are being interpreted in a different order in production/development
- Pass Parent Component ComponentDidMount data to Child ComponentDidMount
- React unit testing const arrow function
- Not sure why `Justify-Between` keeping everything at the beginning of container
- React devToolsExtension breaks the store
- React Navigation 5 - Reset a stack (similar to popToTop()) from another stack in a different tab before navigating to it
- How to Set a Fallback Value in React?
- Pass method with parameters through react props?