how to add function to react functional component object so that we can call component.function()
const ReactComp = () => {
const func = () => {return}
return (<div></div>)
}
let comp = document.querySelector("react-comp")
comp.func() // need function call in this way`
3
Answers
You can achieve this by using the :
here is code sample to achieve your requirement
component.
button.
clicked!" to the console.
Dom elements can only have strings attached to. So in the follwing case
If you are trying to use the event handlers you can do something like e.g. testing
The following is not recommended at all