score:5
Accepted answer
you are mutating state directly but you're also returning a new object via object spreading:
setchecks({ ...checks });
since this creates a new object the component re-renders.
score:0
mutatemycheck(); mutatemycheck();
that won't increase the checks twice.
in this case you should use a reducer.
Source: stackoverflow.com
Related Query
- Why does it matter if I am mutating state in React useState hook?
- React - useState - why setTimeout function does not have latest state value?
- useState react hook does not set the array state
- Why does my WebSocket message handler always get React state hook variable's initial value?
- Why does react re-render twice when using the state hook (useState)?
- useState React Hook set method does not update state immediately in onChange()
- React useState hook does not shows correct state of array
- Why state declared via useState hook does not change?
- Why useState in React Hook not update state
- React does not change state after updating state in usestate hook (in custom function form)
- Why does useState react hook cause Too many re-renders. React limits the number of renders to prevent an infinite loop
- Why does useState react hook cause Too many re-renders. React limits the number of renders to prevent an infinite loop?
- Why does calling react setState method not mutate the state immediately?
- Why React Hook useState uses const and not let
- React useState hook event handler using initial state
- Mutating state from React's useState hook
- React - weird behavior when useState hook sets state for the first time vs subsequent times
- Updating Parent Component State from Child Component with UseState React Hook
- React w/ TypeScript: why is the type for the state lost when useState with a callback as the updater
- Why does the 'useState' hook invoke the initial state when it's a function reference?
- Why does react hook throw the act error when used with fetch api?
- How to use React Context with useState hook to share state from different components?
- Why does null React component state initialization get `never` type?
- Why does React have to use setState for state update?
- Set multiple state values with React useState hook
- Better way to use useState hook for setting the boolean state in React
- why filtering state array with react hooks doesn't work but filtering original array does
- Why does calling the set function of a useState hook apply immediately in async functions?
- How does React useState hook work with mutable objects
- Why does each state hook update cause a separate re-render in asynchronous code?
More Query from same tag
- Problems with React Redux store passing props to children
- How can I force React to re-render all components on a page that come from array.map?
- how to display a random value from an array of objects in an React view
- Is there any way to call the api and save it using useState in reactjs?
- Making conditional async call with same parameters in Typescript React
- Pan and zoom on an "infinite" graph paper background in js
- How to decorate Google Line Chart using react-google-charts plugin
- Change background-color of an unchecked Material-UI checkbox
- Filter books according to the book types and advanced types (React.js, MongoDB, Express)
- How to pass data from child to parent when a list item is clicked
- Access HTML by id through SASS
- Refactor a React component from function to ES6 class
- How does React's state hold files through use of spread operator?
- Deploying Create React App to a subdirectory but make API calls to parent path
- event.stopPropagation() fails on ReactJS Component inside a native HTMLElement
- How to Implement Price Increase and Decrease Sorting in React Redux Application?
- React Router & Express Conflicts
- Jest configuration error in React+Typescript+Webpack project
- How to push event targets to an object in an array in state with onChange and setState()
- Reactjs: How to check data in array if it is exist or not?
- add sitemap file to google search console
- How to send data and photo at same time to node js backend using axios in react js
- ReactJS + Redux: Why isn't MongoDB saving data to the database even with correct API requests?
- React function component not updating with new props
- Use scoped packages with Jest
- Axios API Twitter request not returning back user tweets
- React router 4 - Why is my component only rendered on manually setting the url but not on clicking a Link with same url?
- Translating from React to Mithril 2? (a Meiosis example)
- How to save cookies in browser using GO + REACT?
- How to bind value of btn REACT?