Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 527 Bytes

use-emit-event.md

File metadata and controls

27 lines (19 loc) · 527 Bytes

useEmitEvent

Easily emit a browser event using dispatchEvent and CustomEvent

MDN docs

Example

import { useEmitEvent } from "@casperiv/useful/hooks/useEmitEvent";

const Component = () => {
  const { dispatch, event } = useEmitEvent("MyCoolEventName");

  console.log(event);

  const handler = () => {
    dispatch();
  };

  return (
    <div>
      <button onClick={handler}>Dispatch the event!</button>
    </div>
  );
};