useWindowEventListener

About

Adds an event listener to window

Examples

Basic usage

import { useState } from "react";
import { useWindowEventListener } from "rooks";
import "./styles.css";

export default function App() {
  const [value, setValue] = useState(0);
  useWindowEventListener("click", function() {
    setValue(value + 1);
  });
  return (
    <div
      className="App"
      style={{
        padding: "20px",
      }}
    >
      <h2>Click anywhere</h2>
      <p> Value is {value}</p>
    </div>
  );
}


Join the community!

Join our discord server! You can click the floating discord icon at the bottom right of the screen and chat with us!

Powered by vercel