const App = () => {
return (
<div>
<div
onClick={() => {
console.log("Inner div");
}}
>
Inner div
</div>
</div>
);
};
ReactDOM.render(
<React.Fragment>
<App />
<div
onClick={() => {
console.log("Outer div");
}}
>
Outer div
</div>
</React.Fragment>,
document.getElementById("impact")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js"></script>
<div id="impact"></div>
I have a simple code written using react and built with Webpack 5. The problem is that click by "Inner div" doesn't work but click by "Outer div" works good. When I pass an inline template to ReactDom.render function, onClick works, but if I use a functional component, it doesn't. What can cause this behavior? Maybe the problem is with Webpack config?
You can use this repo to reproduce the problem: https://github.com/nikitabelotelov/react-click-bug-reproduce