1.1.5 • Published 3 years ago

use-stable-callback v1.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

useStableCallback

A substitute for useCallback that returns a memoized version of whatever callback that it is given.

The returned function maintains a stable reference, but it will always have accesss to the most recent scope of the component in which it is used.

function MyComponent({ url }: { url: string }) {
  const refreshData = useStableCallback(() =>
    fetch(url, { method: 'GET' }).then(r => r.json())
  );

  return <SomeChildComponent refresh={refreshData} />;
}
1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago