score:4
Accepted answer
you have to use onclick like this
onclick={()=>setselected(section)}
score:2
if you want to add a value to a function you should use an inline function inside the onclick. right now you are triggering the function for each rendering at render time.
change:
onclick={setselected(section)}
to:
onclick={() => setselected(section)}
Source: stackoverflow.com
Related Query
- React .map function not passing data to useState
- How to fix map is not function even there is already set data in the useState using React Hook
- useState not updating data when passing from parent function component using ref
- Map function not working while passing props into React component (TypeScript, React and Next.js)
- Map is not a function when passing data to populate child component
- diaplays same data in react js, if condition not working or working but map function takes all value without sorting
- Unable to update a list with react when its value is being changed using the hook useState function from React TypeError: map is not a function
- map function not working for API data in useEffect - React Hooks
- React display data from object TypeError: value map is not a function
- Calling React useState and passing it a value... Which returns to me that, SetCurrentId is not a function
- React - useState - why setTimeout function does not have latest state value?
- map function not working in React
- passing data from child to parent component - react - via callback function
- React - State Hook map is not a function
- React - State Hook map is not a function
- axios.post().then() not passing resolved data to callback function
- React - mapping data to rows that are formed during a map function
- React - Adding component in Map function not adding
- React JS printing data inside a nested map function in JSX
- Passing data from one function to another in React
- react map is not a function
- Edit function not saving changes to state data in React
- React router dom passing data from parent component to child router component does not pass the props.match
- How to access data within map function for onClick in react
- Map function in react (err: TypeError: e.map is not a function)
- React stateless component where map function is not returning
- React useState hook (and useEffect) not working in callback function
- react useState and setState claims calendarList.push is not a function
- The state variable returned after using useState react hook shows .map is not a function
- React function not passing down from functional to functional component
More Query from same tag
- TypeError: Cannot read property 'toLowerCase' of undefined in React-hooks
- use middleware to manage localStorage/cookies
- How to clear browser back button history in react-router-dom
- Paginaton with ReactJS
- react firebase custom fields authentication create user is not storing the custom fields in firestore database collection
- ReactJS app using Three.JS. How to render the VRButton?
- How to structure the css files in reactjs in a way that it follows the concept of component separation
- Bad Request React Axios 400
- Integrate Google Analytics Measurement Id with React JS
- How to compare prevProps with this.props in shouldComponentUpdate
- React: Does order of assigning state versus binding functions matter?
- Socket.io and React: Proper way too receive data from server and set state in a component?
- Typescript + Parcel new JSX transform - React is not defined error
- refresh the table after update
- Cannot read property 'target' of undefined
- Mock keyboard event and test stopImmediatePropagation is called with React
- How to verify a user's ID token in firestore using Javascript?
- Overcoming lack of refs in stateless components
- Is there a way to eliminate the extra click my game currently requires to restart?
- Axios Api calls in Heroku
- Why is my onClick being called on render? - React.js
- React map through an array of objects and arrays
- display selected row of json data in reactjs
- How to add logical if statement when rendering React components?
- React: Higher Order Components: Can you can childs state
- Error: Prevent writing to file that only differs in casing or query string from already written file. reactjs laravel
- In React how to add key prop to element passed as Object
- Render images from files array on client with Reactjs
- Sizing the MUI CircularProgress
- Redux form "submiting" value not goes true on form submit