In the event object event in react, target is viewed as null, in the console, but event.target can get the target element. why?

Code:

input:

Why does event.target get it correctly for the determination below null,

Mar.20,2021

this is because the events in React are not real DOM events, but rather composite events encapsulated on native DOM events.
Composite events are managed by the event pool, the composite event object may be reused, and all properties of the composite event are emptied. So when accessing the properties of a composite event in an asynchronous handler (such as setTimeout, etc.) or in the browser console, it may be empty.
the solution given in the answer above: event.persist (), simply removes the current composite event from the event pool, so you can continue to have a reference to the event and still have access to the event's properties.


event is only the current object
default react sets all its properties to null


function(e){
          e.persist()
          console.log(e);
        }
Menu