score:4
it's pretty easy to do that you just need to add onclick handler to the renderitem section.
renderitem = {(item, index) => (
<list.item key={item} onclick={() => this.handleclick(index)}>
<list.item.meta
avatar={
<avatar src="https://zos.alipayobjects.com/rmsportal/odtlcjxafvqbxhnvxcyx.png" />
}
title={<a href="#">{item}</a>}
/>
</list.item>
)}
and for the handleclick function the code will be:
handleclick = index => {
const selecteditem = this.state.data[index];
}
selecteditem is the one you are looking for
score:1
the above solution should work. but just ensure that you are attaching onclick
event to a dom element. if it is a custom component then event handlers won't work. so, in this case list.item
(i guess that it is a custom component) needs to access onclick
as a prop and attach this event to its top most dom element like the follwing:
// list.item
<li onclick={this.props.onclick} />
Source: stackoverflow.com
Related Query
- How can I get the selected item from List in React?
- react native - How can get the list of "dog" from the sqlite table?
- How can I get a variable from the path in react router?
- How can I get the value from an animated or interpolated value in React Native?
- How to get the selected value from a radio button group in React where there are multiple groups?
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- how to pass the current item to the function so that i can remove it from array in react component?
- How do I access the index of a selected item in list using React and Material UI?
- How can i get access to the current user inside of react from firebase?
- How can I get token from the URL in Nextjs / React App?
- How to get the value of selected option from React hooks?
- How can I get the right data from database with react
- How can I get the jsessionid from a response using react js?
- How to get the index of the selected item from a dropdown in ReactJs and material UI?
- How can I get selected data list and structure the data list
- how to get selected item in an array from another functional component react
- How can I get the title of the list item the user wants to save
- How can I get the native PIXI object from a react-pixi-fiber React component?
- How can I pass the selected date(value) from react calendar to another component?
- How would i get the selected from my autocomplete box using material ui library in react
- How can i target a specific item from a list of array on Hover in React
- How can we get the input text from multiple dynamic textareas in react hook?
- React - How can I get the values from my multiple input and send them to my input?
- How can I get the 1st image from each album with an even ID in React using Fetch?
- How can I get the href id from a react route?
- How can I grab the key of a list item generated from a map function?
- How can I get the uncheked value from checkbox in React
- How can i get the Video duration of a selected video from input in ReactJs?
- How can I update the data in my list if a subitem updates from a get request in RTK Query
- How to get values from the selected radio button in react js
More Query from same tag
- Command "yarn run build" exited with 1. Vercel deploy
- Converting componentDidMount into useEffect
- function gives me TypeError: Cannot read property 'resize' of undefined
- React - setting state
- Problem with setting state after fetching data (React hooks)
- function use prev state not current state
- React Fontawesome Icon on Button not Allowing Id to be Accessed
- how to maintain login and logout state globally and reflect the changes, when localstorage is used to save login and logout state globally in reactjs
- React Component won't render new state even after rerender
- How to use Webpacker for React on an existing Rails 5.0.2 application?
- How to show imported svg icon in react?
- How to send props dynamically to styles hook in material UI?
- React Port 8081
- command to apply changes in react for ubuntu server
- How to define a img tag inside a React.createElement() in React?
- Trying to change my data during a .map call
- Serving static assets during development with WebPack
- React displaying relative time with javascript
- Redux Form Typescript Pass Custom Props
- What is the recommended approach for large react app with react-query?
- Webpack pdf file loader
- input allows to write 1 symbol only
- Can't create WebStorm React project
- Why React component is not update when the props passed to it changes?
- React accessing a parent method from generated children components
- reactstrap not displaying the selected default value/value within the dropdown list
- How to get field from multiple-layer document in Firestore
- How to useStyles based on props inside a breakpoint with material-ui
- React selectively not passing new props to rendered object
- Accessing data from local file by id (from params, React Router v6)