Coder Social home page Coder Social logo

therakeshpurohit / react-use-event-hook Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scottrippey/react-use-event-hook

0.0 0.0 0.0 188 KB

Same as React's useCallback, but returns a stable reference.

Home Page: https://www.npmjs.com/package/react-use-event-hook

License: MIT License

JavaScript 46.25% TypeScript 53.75%

react-use-event-hook's Introduction

react-use-event-hook

Same as React's useCallback, but returns a stable reference.

This library is a user-land implementation of the useEvent hook, proposed in this RFC.

Installation

npm install react-use-event-hook

Usage

(this example was copied from the RFC)

You can wrap any event handler into useEvent.

import useEvent from 'react-use-event-hook';

function Chat() {
  const [text, setText] = useState('');

  const onClick = useEvent(() => {
    sendMessage(text);
  });

  return <SendButton onClick={onClick} />;
}

The code inside useEvent β€œsees” the props/state values at the time of the call. The returned function has a stable identity even if the props/state it references change. There is no dependency array.

See more

react-use-event-hook's People

Contributors

lynxtaa avatar scottrippey avatar shkreios avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.