score:2
Accepted answer
in the first option you are trying to modify the state directly which is not allowed in react's usestate
and that's why it is not rendering your expected change.
the problem with the second option is your are trying to use {}
instead of []
. try as:
let prevfilters = [ ...filters ];
the reason behind is .map()
is a function on arrays and not on objects.
Source: stackoverflow.com
Related Query
- React map function stop working on state update
- React Native: How to stop map markers from re-rendering on every state update
- Map function won't work after react state update
- How to Update State in map function in react
- Change Value of State Nested Object in React js - Map Function isnt working
- How to update state of child component when it get called in map function from parent component React JS
- map function not working in React
- React hooks function component prevent re-render on state update
- React idiomatic way to update Map object in state
- React - State Hook map is not a function
- React - State Hook map is not a function
- How to update state in map function in reactjs
- Stop function is not working as expected. Need Help. React
- React Hooks State update one step behind. For this reason my changes are not working correctly
- React Conditional state update not working
- Warning: Can't perform a React state update on an unmounted component. useEffect cleanup function
- Waiting for react state to update in function component
- React Hooks state not working properly when the function calling it is called in another function
- React hooks: Can't update state inside function component
- Working of push in react while using redux to update the state
- How to use map function on react state hook
- React Js Map function not working on a nested array
- How to prevent a state update on a react onClick function (outside useEffect)?
- React lifecycle hooks not working on redux state update
- how do i update state in react for updating the value of an object inside an array using array.map function
- map function on React state - state with fetched API data
- Map function not working while passing props into React component (TypeScript, React and Next.js)
- map function not working properly in object React
- OnClick event not working in map function react
- Can't perform a React state update on an unmounted component problem in Interval function
More Query from same tag
- In my react app I am importing mobile styles that are being overridden by general stylesheet
- Sending Azure token to API back-end keeps returning 401 Unauthorzied error when OnTokenValidated is added to the API
- Fetching json api using react ( useeffect )
- How to organize state with redux and react-router?
- Module not found: Error: Can't resolve - Parsed request is a module
- How to insert bootstrap.js to react app?
- Warn: State updates from the useState() and useReducer() Hooks don't support the " + ... MERN Stack Application
- How to check if component returns false in react?
- How can I upload multiple files in a React form to Flask API?
- React pending promise while after fetching from express backend
- Not able to display bootstrap table using map function
- When I render a button inside a material-ui table, the button is not clickable
- How can I center my clip-path's text relatively to the viewport and display all the clip-path's text?
- Making use of the key attribute in React JS
- Get message id from notistack snackbar
- ReactJS - {this.props.children} is undefined
- react-leaflet-search component not rendering
- React-Select inside react-select
- React Link to open new tab
- React DatePicker calendar showing behind table head
- event.stopPropagation() after Escape key pressed removed from v2 of react-select
- React Joyride-How can I adjust position of floater?
- How to use a bootstrap load spinner while fetching data from an external api?
- net::ERR_CONNECTION_REFUSED to cube.dv
- How to set State after mapping over an array and object in react/JS?
- setState in infinite loop inside render
- Why am I getting 'Each child in a list should have a unique "key" prop error' When I have a key assigned?
- How to pass django user authentication data to react app?
- How do I load arrays to map into columns with multiple rows?
- React Native: Lottie Animations flicker on Android, but not iOS