GithubHelp home page GithubHelp logo

react-18-event-issue's Introduction

React 18 event issue

React version: 18.2.0

How to reproduce

Working way using ReactDOM.render

  1. Run the app (npm start), it will display a page with a button
  2. Open the Javascript console (browser's dev tools) to see some logs that will appear (Note that you should see the React warning about using the deprecated ReactDOM.render function)
  3. Click on the button, a popup shows
  4. Click anywhere on the window, it will close the popup

Not working way using ReactDOM.createRoot

  1. Change the value of the ENABLE_NEW_REACT_18_CREATEROOT in file src/index.tsx to true (The page should reload)
  2. Click the button, ... and nothing happens (well graphically at least, because in the console, we can see that the popup is closed right after opening)

Quick fix

A quick fix is to uncomment the line 32 (event.stopPropagation()) to make it work again.

It looks like, with the new ReactDOM.createRoot function, that the popup rendering is done before the processing of the initial button's click event is even finished...

Alright, we are messing up with window event listener there. But that's because we want the popup to close on any click on the window. Maybe there is a better way for doing that properly?

react-18-event-issue's People

Contributors

vinorcola avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.