In my case, I have to wrap up the content in the parent component without adding extra div element to the DOM. So, I wrapped the element with the react fragment. I got a use case to add the native browser event to the react fragment, Is that even possible?
Short answer, no, you can't add events on React Fragments. There is a detailed discussion over here, but as such, I don't think React Fragments will be supporting event handlers in the near future.
You may convert the your React Fragment (from <> </>
) to a div element instead, and attach events to them.
return <div onClick={() => handleClick()}> </div>;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With