vituarvom / react-smart-utils

A simple, smart hooks and utility functions to make development easier
https://www.npmjs.com/package/react-smart-utils
13 stars 34 forks source link

Implement useEventListener hook #23

Open bharat-dussa opened 2 months ago

bharat-dussa commented 2 months ago

useEventListener

Description: A hook that simplifies adding and removing event listeners on a specified target (e.g., a DOM element or the window object). This is useful for handling events like clicks, key presses, and resizing in a functional component.

Parameters:

Returns:

Example:


import React, { useState } from 'react';
import { useEventListener } from 'your-library';

const ExampleComponent = () => {
  const [count, setCount] = useState(0);

  // Define the event handler
  const handleClick = () => {
    setCount(c => c + 1);
  };

  // Use the useEventListener hook to listen for clicks on the window
  useEventListener('click', handleClick);

  return (
    <div>
      <p>Click anywhere to increment the count: {count}</p>
    </div>
  );
};
Laxman8261 commented 2 months ago

i am interested @bharat-dussa pls assign me to this issue

bharat-dussa commented 2 months ago

Okay

nikkivaddepelli commented 2 months ago

I would like to work on this issue. Can you please assign this to me?

bharat-dussa commented 2 months ago

I would like to work on this issue. Can you please assign this to me?

Already assigned to @Laxman8261 , please pick another one