Im having an issue. When you click listItem
(whole separated li
element) I want to call the onChange
function on the checkbox component inside listItem
.
I could easily move that function from checkbox to parent but I will loose the checked
prop.
Checking the checkbox itself doesnt work, but just open the console to see the results. I want handleToggle
function to fire properly when whole element is clicked (not only checkbox)
<List>
{['first', 'second', 'third'].map((name, i) => (
<ListItem key={i} dense button>
<ListItemText primary={name} />
<Checkbox
disableRipple
checked={false}
onChange={(evt, checked) => this.handleToggle(evt, checked, name)}
/>
</ListItem>
))}
</List>
Edit
I don't want to use state in this component at all. Summarizing - how to pass event from ListItem
(parent) to it's children (Checkbox
)?
Final edit: I've found out the way how to deal with it. No state needed. Just two simple lines of code.
Since checkbox state is fully controlled by redux, I just moved the onClick
func to the ListItem
element with one line on code in it's body:
...dispatch(toggle(!this.props.elements[nameOfElement], name));
Anyways thanks to everyone for help. Upvoted every answer.