0.1.22 • Published 9 months ago

react-dom-event v0.1.22

Weekly downloads
-
License
MIT
Repository
github
Last release
9 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

10 months ago

0.1.10

11 months ago

0.1.22

9 months ago

0.1.12

11 months ago

0.1.13

11 months ago

0.1.14

11 months ago

0.1.15

11 months ago

0.1.16

10 months ago

0.1.8

11 months ago

0.1.17

10 months ago

0.1.7

11 months ago

0.1.18

10 months ago

0.1.19

10 months ago

0.1.9

11 months ago

0.1.6

11 months ago

0.1.4

2 years 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