score:1
Accepted answer
you appear to be missing a square bracket in your example code:
| null>(['')
should be
| null>([''])
change line 8 so you're also spreading the second array, and it fixes your problem:
setarr((prev: string[])=> [...prev, ...temparr])
Source: stackoverflow.com
Related Query
- Correct way to push into state array
- What is the correct way to push jsx with embedded js variables on to an array
- Correct way to push an item to array in javascript
- Proper way to manipulate date string with wrong year, but correct time
- Correct way to push in string[] react+typescript
- Correct way to handle conditional styling in React
- Is this the correct way to delete an item using redux?
- Correct way to share functions between components in React
- Correct way to type nullable state when using React's useState hook
- Correct way to create event handlers using hooks in React?
- What is the correct way of adding a dependency to react in your package.json for a react component
- Correct way to define an empty dom element in React
- React i18next and correct way of changing language
- Correct way of error handling in React-Redux
- Correct way of Creating multiple stores with mobx and injecting it into to a Component - ReactJs
- Correct way to check if any object is a SyntheticEvent?
- Correct way (if possible) to store JSX code into a Javascript variable
- Correct way to throttle HTTP calls based on state in redux and react
- What is the correct way to access props in the constructor?
- Correct way to handle undefined declaration files (index.d.ts)
- TS2322 Error when extending Button, component property not found. What is the correct way to type?
- What is the correct way to animate/transition between routes in react router
- React Redux correct way to handle error / success messages unique to each component
- Correct way to programmatically fill a ReactJS input
- What is the correct way to use inline style in react?
- Correct way to catch fetch errors in React?
- Correct way to pre-load component data in react+redux
- How is the correct way to have multiple dataProviders in react-admin?
- Correct way to define handlers in functional React components?
- What is the correct way to extend Material UI ListItem?
More Query from same tag
- Function onChangeAnswers in the checkbox what he does
- Using Hooks + Callbacks
- SSR with Helmet also render async meta and content?
- How to the data to be loaded from file/api for first render and from the state for subsequent render in react, redux?
- How to remove CSS 'active' class if clicked element is already 'active'?
- Immutable Update React Hooks Array Object
- Is it possible to use Sass variable within styled-component @media query?
- How to spy on a method which is called inside componentDidMount
- Onclick rerouting to url although button is disabled
- How to stop auto sliding of react-bootstrap carousel
- How to input decimal places in Textfield from MUI in react
- React Image upload Dropzone
- Failed to execute 'send' on 'WebSocket': Still in CONNECTING state
- How to map to URL in a bootstrap table?
- How to create a reusable component or partial in react.js?
- How to separate out a JSON Object for a reusable React table component
- display all data with only a single object from array of objects
- How to change parent component's state from child component?
- Loading local JSON file in React for dynamic content
- React - assign component to array variables
- Issue with selecting object properties with import
- React: How can I map nested JSON Objects without key name
- Nested route not working in React
- Axios POST promise not working as expected
- CSS breaking after adding conditional checks in return method for an unordered list
- React-Js - Making POST request using useEffect and
- show name of the user on hover on material ui Avatar component
- Display a component on clicking a button in React
- Material-UI tab not displaying component report on page render
- How to use highly compressed bundle file (bundle.tar.gz) for hosting in server?