Reputation: 639
I have material ui components like:
<ListItemText onClick={(ev) => onAreaSelect(ev)} primary={area} />
</ListItem>
And then:
const onAreaSelect = (event) => {
console.log("area seledcted??", event.target, event.target.value)
}
event.target
returns:
<span class="MuiTypography-root MuiListItemText-primary MuiTypography-body1 MuiTypography-displayBlock"> Area </span>
but event.target.value
returns:
undefined
how can I access the value?
Upvotes: 0
Views: 552
Reputation: 46
I faced a similar problem and came up with a work through around this.. you can pass the "area" with event in your function onAreaSelect
For example like this:
<ListItemText onClick={(ev) => onAreaSelect(ev,{area})} primary={area} />
</ListItem>
const onAreaSelect = (event, area) => {
console.log("area selected??", event.target, area)
}
Upvotes: 1
Reputation: 657
useRef()
which will hold the value of the element you put ref
field in like so:
const areaRef = useREf(null)
.
.
<ListItemText ref = {areaRef} onClick={(ev) => onAreaSelect(ev)}
primary={area} />
onChange()
has two params : event and value so you can do something like this :
onChange((event,value)=>onAreaSelect(event,value))
Upvotes: 1