vituarvom / react-smart-utils

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

Implement useEventListener hook #23

Open bharat-dussa opened 1 week ago

bharat-dussa commented 1 week 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 1 week ago

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

bharat-dussa commented 1 week ago

Okay

nikkivaddepelli commented 1 week ago

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

bharat-dussa commented 1 week ago

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

Already assigned to @Laxman8261 , please pick another one