score:2
Accepted answer
you have to create an arrow function as such:
onchange={()=>console.log(item.option_image.alt)}
what you are doing now is simply accessing the onchange method.
notice the difference:
with onchange={(e) => onchange(e)}
, you are essentially creating a new function that calls onchange method during each render.
with onchange={onchange}
, you are directly accessing onchange method.
score:1
you need to do it like this:
onchange={() => console.log(item.option_image.alt)}
if you don't do it like this, it will run the console on the first load of the page, not when the radio is clicked.
Source: stackoverflow.com
Related Query
- method onChange not working in radio button
- React 16 Radio Button onChange not working
- React radio button onChange event does not bind on first change of radio button
- Radio button not working
- Radio button not working correctly when rendered using array Data
- How to check the Radio Button in Cypress. The regular check() is not working
- react testUtils simulate click on a radio button not triggering onchange
- React useRef / forwardRef not working as expected when focusing a radio button
- Checkbox property DefaultChecked in reactjs not working with states updated by radio button
- setting defaultChecked in radio button is not working in react
- Radio button onChange event not firing
- My onchange method is not working in react
- onChange method is not working on all the fields
- this.props.history.push not working in method for onChange
- Chrome Extension: JS DOM button click method is not working
- Not getting the method to pass id and value of radio button as parameter with react.js
- React onChange method not working in react_on_rails
- Material-ui radio button not working together with react-final-form
- ReactJS - radio button onChange event not firing
- TouchableOpacity and button not working in react native Modal?
- react-hook-form's setValue method is not working if input is in material ui dialog
- React-Native Button onPress not working
- React select onChange is not working
- React-Bootstrap ONLY Close Button Styling Not Working
- onKeyUp not working in React where onChange did
- Prev and Next button is not working correctly at the breakpoints
- ReactJS & Google MDL Button onClick not working
- ReactJS, material-ui TextField onChange not working
- Why is OnChange not working when used in Formik?
- react-select onChange not working after change options
More Query from same tag
- How to use react-swipe as a component?
- React Hook useCallback has a missing dependency:
- Best way to keep track of disabled fields on redux-form
- TypeScript Error: (TS1128) Declaration or statement expected
- How to put a button on the top right corner of a multiline textfield of material ui
- Framer motion and exit property not working with InertiaJs
- How to create custom reusable icon component in React.js
- Can I mapDispatchToProps without mapStateToProps in Redux?
- How to set object state in react
- Import React in Node.js throws SyntaxError: Unexpected token export
- Setting up JWT - Passing token from server to client in header, but cannot parse header in client
- Typescript error "children does not exists on type IntrinsicAttributes & RefAttributes<unknown>'.* " on react component
- Antdpro Table column is not working when state changes
- Tag <ErrorMessage> Formik react Style
- React testing library difference between snapshot and debug output
- React/DC.js - Chart Resizing (based on window size)
- Pseudo element not showing in React on paragraph tag despite using display block
- How can I add a dynamic Id to array of object
- How to avoid unnecessary render in React using Hooks API
- Connect redux to a single react component
- Using styled-components
- html5 getUserMedia Cannot set property 'srcObject' of null
- My topbar duplicates since adding axios and importing the user image with axios and react
- How to put an image on top of the view of the camera with react-native
- What is a better way to identify which route i am currently on with react-router 4
- Conditional rendering of a static partial in react - MERN
- Retrieve the index of image on click ReactJS
- Best way to set translated document title (HTML tag) in React with react-i18next
- How to fix this ESlint (no-param-reassign) error in my Filter
- How can I show the card I bought Antd side by side?