4 ms·
> I guess they just call that function from within the Data component with the correct parameter. Yep > Is there a better way? We're experimenting with some
by dounan 9y ago
> I guess they just call that function from within the Data component with the correct parameter.
Yep
> Is there a better way?
We're experimenting with some other options internally. Once we have a better sense of what works best, we will post another article on our learnings :)
- doctorcroc 9y agoAssuming your "deleteDataAt" function is a Redux action creator that dispatches an action to delete the list item -- if this is the case, then continue passing that action creator as a prop to the child, and since you've also passed down the index, the child can simply apply that action creator as the event listener. Eg. in the code snippet you've provided, I would have just done: return ( <Data value={d} index={i} deleteDataAt={deleteDataAt} /> ); Then your onClick in the child would be: onClick = (_e) => this.props.deleteDataAt(this.props.index); Correct me if I'm missing anything!
- dounan 9y ago> Correct me if I'm missing anything! You're not missing anything :) That approach also works. The important point is that you have to pass the extra index prop down to the child to avoid the bind in render.