this is my react hooks code:
function Child({lookup}){
var [count,set_count]=React.useState(0)
function diff(){
set_count(count+1)
}
lookup.diff=diff
return <div>{count}</div>
}
function Parent(){
var [lookup,set_lookup]=React.useState({})
return <div>
<Child {...{lookup}}/>
<button onClick={_=>lookup.diff(1)}>up</button>
</div>
}
ReactDOM.render(<Parent />,document.querySelector('#root') );
This code demos a simple way to call a child component inner method from a parent component. it works as planned but uses coding tricks that I didn't see anywhere else. I am pretty much sure it is not idiomatic.
my question is: based on how react hooks works, will it potentially crash in some unexpected ways?