1.1.5 • Published 2 years ago

use-stable-callback v1.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 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

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago