@react-hook/latest
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "@react-hook/latest", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/latest#readme", | ||
@@ -5,0 +5,0 @@ "repository": "github:jaredLunde/react-hook", |
<hr> | ||
<div align="center"> | ||
<h1 align="center"> | ||
@react-hook/latest | ||
useLatest() | ||
</h1> | ||
@@ -37,3 +37,13 @@ </div> | ||
```jsx harmony | ||
import _ from '@react-hook/latest' | ||
import useLatest from '@react-hook/latest' | ||
const useEvent = (element, name, listener) => { | ||
const latest = useLatest(listener) | ||
React.useEffect(() => { | ||
const listen = (e) => latest.current(e) | ||
element.addEventListener(name, listen) | ||
return () => element.removeEventListener(name, listen) | ||
}, [latest]) | ||
} | ||
``` | ||
@@ -43,7 +53,13 @@ | ||
### useLatest(value) | ||
```ts | ||
const useLatest: <T extends any>(current: T) => React.MutableRefObject<T> | ||
``` | ||
### Props | ||
| Prop | Type | Default | Required? | Description | | ||
| ---- | ---- | ------- | --------- | ----------- | | ||
| | | | | | | ||
| Prop | Type | Required? | Description | | ||
| ----- | --------------- | --------- | ------------------------- | | ||
| value | `T extends any` | Yes | Any value you want stored | | ||
@@ -50,0 +66,0 @@ ## LICENSE |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10798
67