reactjs - Pass callback with parameters to parent component -
i asking trivial has been bugging me while.
lets have child component renders buttons:
const picker = ({ data, label, visible, cancelcallback, onpresscallback }) => { function renderrow (data) { return data.map((el) => { return ( <touchableopacity style={listviewitemcontainer} key={el.label} onpress={} > <text style={listviewitem}> { el.label } </text> </touchableopacity> ); }); } return ( <modal visible={visible} animationtype="fade" onrequestclose={() => {}} transparent={true} > <view style={listviewcontainerstyle}> { renderrow(data) } </view> </modal> ); };
now when press 1 of buttons want make callback parent want pass parameters label of element pressed. like:
<touchableopacity style={listviewitemcontainer} key={el.label} onpress={onpresscallback(el.label)} // onpresscallback prop passed child > <text style={listviewitem}> { el.label } </text> </touchableopacity>
and handle logic in parent component. how can this?
like this.
onpress={() => onpresscallback(el.label)}
Comments
Post a Comment