in tutorials I'm seeing something like that :
import React from 'react';
function App(){
return(
<div>
<h1 onClick={functionName}>Hello React</h1>
</div>
);
}
export default App;
but I think adding "onClick" event to an element is a bad practice , instead we were adding event listener with vanilla JS , but now . I don't know if it is OK or not in reactJS? is there better way or this is what it is ?
addEventListeneris bad practice in React. Let React handle events. Use theonClickproperty. Otherwise React may not know about the event. Note that theonClickin React is not the same as DOMonclick. It is a synthetic event. React will handle it internally or dispatch it to the DOM as appropriate