“event.persist ()” Kode Jawaban

event.persist ()

 handleClick(event) {
        event.persist();
        this.setState((prevState) => ({
            foo: prevState.foo + event.pageX
        }));
    }
Brave Badger

mengapa menggunakan event.perist

//Without event.persist() , 
//React will make the first event value as null when second event is fired.

//How to use?

const handleFilterChange = (event) => {
    event.persist();
    setFilters(currentFilters => (
      produce(currentFilters, draftFilter => {
        draftFilter[event.target.name] = event.target.value;
      })
    ))
  };
Rey

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya