score:2
Accepted answer
You can use Array.slice which returns a shallow copy of your original array minus the sliced items. DO NOT use shift() which actually mutates your state and can cause all sorts of issues.
return [...state.slice(1), action.payload.stream]
score:0
Array#shift
returns the shifted value, not the array with the value removed (it shifts it in-place).
You can do
state.shift()
[ ...state, action.payload.steam ]
although I'm pretty sure Redux docs specify that you should avoid acting on the state directly...
Source: stackoverflow.com
Related Query
- How to add one item to the top of a redux store list while removing the bottom item from the list
- How to fetch data in getInitialProps with redux-saga.Then get the response from redux store while in the getInitialProps method?
- How to stop re-rendering a whole list of items when only one item of the list is created or updated in ReactJs React-Redux?
- How to make the first item of the list always be at the top and the rest of the list will scroll independently of it
- How to disable one of the list item in PrimeReact ListBox?
- How can I get more than one value from the Redux store in a single statement?
- How to sort the antd-table while keep one special line forever on the top of the table?
- How do I add a title and close button to the top of a menu (above the 1st item in a button menu when clicked in material-ui?
- How to consecutively add values from one array to another and store the value in a new array in javascript?
- How to render and add similar item to the list of items from the api in React.js?
- How can I get an item in the redux store by a key?
- React Redux Cant add item into list in the state
- How to add a button that deletes an item from the list in react.js
- How to use redux to add todo item in todo list
- How add an object into the array list that is value of another object in Redux toolkit
- react - how to add item to list multi-times one frame
- When I click the delete button the top item on the list deletes. How can I fix it?
- How to design a Redux Store for a list which maintains the selection state
- how to re render a list after updating an array state in a position in between (not at top or bottom in the list)?
- While debugging, can I have access to the Redux store from the browser console?
- How to show a loading indicator in React Redux app while fetching the data?
- Redux How to update the store in unit tests?
- How to update the Redux store after Apollo GraphQL query returns
- Removing an item causes React to remove the last DOM node instead of the one associated with that item
- How do I use local state along with redux store state in the same react component?
- How do I add an item to the front of a state array in React
- How to avoid re-rendering the whole List instead of adding the new item to the DOM list in react JS?
- How to access the Redux store outside of a component in React
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
- How to use nested routes to add content to a page without removing the content of the previous route with react-router-v4?
More Query from same tag
- Data from react-hook-form
- ReactJS TypeError: Cannot read property 'push' of undefined
- How to be autheticated in Django backend when autheticated in ReactJs frontend?
- Reset imported js file when back button is pressed
- Error 415 when call POST API using Fetch in ReactJS
- Create a secure layer to hide web service from non-authenticated users, in an React App
- How to get helper function returning promise for React hook function
- state inside custom hook and the main component
- event.target.value returns undefined with semantic UI when I console log it
- ReactJS / Material-UI / Javascript: Can't get rounded borders on TableRow
- Filter array of objects through checkboxes
- TypeError: Cannot read property 'prototype' of undefined React Express
- How do you fix the error in resolving packages when creating a react application
- SOLVED: Filtering results arrays in react client side
- How to read value field in button when it is clicked in react.js
- Redux NODE_ENV errors with Gulp/Browserify
- TypeError: device.devices.map is not a function
- react jest unit test case TypeError: Cannot read property 'then' of undefined
- How to fix wrong alignment of logo in navigation bar?
- Adding image to button using Emotion css
- Running ES2016 unit tests with Jest in BitBucket's Pipelines
- Two dates compare - end date should be greater than start date in validation in react redux
- Prevent background color from overlapping transparent icon
- React Router v4 Google Analytics react-ga
- Having trouble with arrow function in my application
- Scroll to element when clicking table of contents
- Get data from kafka and send it to RSocket
- Nesting in Default Route
- Rendering Text Name as Component in ReactJS
- Google tag manager with react +redux