0.1.22 • Published 4 months ago

react-dom-event v0.1.22

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

react-dom-event

React context for subscribing to all DOM user interaction events.

For a react-native version, check out react-native-event

Example 1

import { Fragment, useCallback } from "react";
import { createRoot } from "react-dom/client";
import { useEvent, EventProvider } from "react-dom-event";

function UseEventComponent() {
  const handler = useCallback((event) => {
    /* do something with any event */
  });

  useEvent(handler, [handler]);
  return <Fragment />;
}

const container = document.getElementById("app");
const root = createRoot(container);
root.render(
  <Fragment>
    <EventProvider events={["click"] /* default */}>
      <UseEventComponent />
      <button type="button" id="demo-1" onClick={() => {}} />
    </EventProvider>
    <button type="button" id="demo-2" onClick={() => {}} />
  </Fragment>,
);

// any click will call the global event handler
document.getElementById("demo-1").click();
document.getElementById("demo-2").click();

Documentation

API Docs

0.1.20

5 months ago

0.1.10

5 months ago

0.1.22

4 months ago

0.1.12

5 months ago

0.1.13

5 months ago

0.1.14

5 months ago

0.1.15

5 months ago

0.1.16

5 months ago

0.1.8

5 months ago

0.1.17

5 months ago

0.1.7

5 months ago

0.1.18

5 months ago

0.1.19

5 months ago

0.1.9

5 months ago

0.1.6

5 months ago

0.1.4

1 year ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago