score:1
that's because you're using single ref for all of your elements. that mean's during the iteration, each element replaces the previous element as the value of content.current. that's why, no matter what element you click, you only get the last one.
you can use something like this instead:
ref={(el)=>el && content.current.push(el)}
and on the click function you can pass the index as well and do this:
onclick={()=>modifyvalueunit(value.valueunit,index)}
const modifyvalueunit = (unit,index) => {
content.current[index].click();
}
Source: stackoverflow.com
Related Query
- When I output the JavaScript map function to JSX, the value comes out strangely
- JavaScript Map Function with React.js gives me index, but not value in the index
- 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
- how to capture the props value inside the event attribute function when use the map function on it
- How to make key value of map function increment for each element in JavaScript
- When I turn off the internet connection it's not showing false value from NetInfo.isConnect function
- state.get is not a function when trying to map the react-redux State
- I am not able to store the returned value of a javaScript function (of Geocoding) in a variable
- Is there a JSX shortcut for assigning a value to a property when it has the same name?
- Get object array from axios and using return value call another axios function and append the output to first result
- react/redux map function doesnt return the value
- Run the javascript before render the page by react JSX function
- return value is not rendering when returned from inside the handleclick() function in react
- map function loop when rendering with ReactJS and concat JSX syntax
- Javascript - Add Item in the middle of an array inside map function
- Retuning a single array object value from the map function on a ternary condition. Problem is it returning both the conditions
- "Unexpected Token" when using the map function in React
- How do I render json data in the javascript function using map - Reactjs
- How to get value of inputs onChange when they are inside map function
- Javascript Map Function Not Storing Correct Value
- Map array to array of JSX components, but only update the right index in the array when there are prop changes
- autoresize textarea when filling out from the element inputs - Javascript
- When a function inside my actions is called it won't work unless I take out the dispatch
- When using map over onClick handler the inner function always gets the last element
- Keep having the error "TypeError: Cannot read property 'map' of undefined" when using map function in React js
- Function keeps on rendering when I try to add to a value to the sum. create-react-app
- Why my variable "intervalId" is not getting the value updated when I call the function "StopTimer" function?
- How can I pass the index from javascript map function to the onclick function?
- React map function does not execute when the component is rendered
- I keep getting [object Object]. when I try to get data from the map function
More Query from same tag
- Is bad to use <input type="date" /> in 2021?
- How to implement onClick componentDidMount() in React using Axios
- react state maps not showing data even after updating the states - react js
- How to Access to first element within an object from each group in js with generated id?
- React, looping through object, displaying list, and grabbing that object when selected
- I am not able to use the router in react js
- Object as input variable in mutation: GraphQL - Apollo - React
- Sort data in Axios response and set as useReducer payload
- read property 'setState' of undefined
- How to make the email input stay on the same page so that user does not have to enter the email again?
- Reactjs - window.addEventListener hashchange only working when component loads initially
- How can I rerender only one item in a flatlist?
- Why aren't components being rendered according to route?
- React router Redirect does not work when route comes from another component
- How to use 2 types of events in typescript interface
- Update useState Object Key Directly?
- Rendering react component using typescript without passing in strongly typed props
- React js fill a map using axios inside a for loop
- How to load MathJax in React?
- ReactJS update simple array onChange of inputs
- How to pass const variable to the event handler
- Materialize css all tabs coming together below each other, but working properly after refresh
- How to make 2 columns with React and Material-UI Grid with only one map to iterate over
- How to fetch json data from a url that requires an api key to access the data in reactjs?
- How to include my Index.html in webpack Production build
- Component is not updating on Button Click, React
- Update existing item or add new item to reducer | React-Redux
- React import folder navigation
- How can I center the scrollable tab?
- Render dynamic html in react js