Using es6 it can be done like this:
this.setState({ myArray: [...this.state.myArray, 'new value'] }) //simple value
this.setState({ myArray: [...this.state.myArray, ...[1,2,3] ] }) //another array
More Related Contents:
- Why is immutability so important (or needed) in JavaScript?
- Update one of the objects in array, in an immutable way
- setState doesn’t update the state immediately
- React setState not updating state
- Trying to use fetch and pass in mode: no-cors
- Rerender view on browser resize with React
- How can I use React hooks in React classic `class` component?
- How do I set multipart in axios with react?
- Updating and merging state object using React useState() hook
- componentDidMount equivalent on a React function/Hooks component?
- Why use Redux over Facebook Flux? [closed]
- How do I update states `onChange` in an array of object in React Hooks
- Client Routing (using react-router) and Server-Side Routing
- setTimeout for this.state vs useState
- How can I disable all typescript type checking?
- How to force a functional React component to render?
- How to print React component on click of a button?
- Using a Set data structure in React’s state
- react-router-dom v6 Routes showing blank page
- react-router (v4) how to go back?
- React hook useEffect runs continuously forever/infinite loop
- Custom _app and _document get ignored when moving files to src/pages folder in Next.js
- How can I dispatch function in redux?
- React Router BrowserRouter leads to “404 Not Found – nginx ” error when going to subpage directly without through a home-page click
- Destructuring of es6 but passing dynamic variable
- Deep nested array of objects not rendering
- updateProfile is not a function (Firebase)
- create-react-app is showing all my code in production, how to hide it?
- Why would we use useEffect without a dependency array?
- Get scroll position with Reactjs