Skip to content

Commit 0406836

Browse files
committed
[event] should use async effect hook
1 parent 0b9239c commit 0406836

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

packages/event/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@react-hook/event",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/event#readme",
55
"repository": "github:jaredLunde/react-hook",
66
"bugs": "https://github.com/jaredLunde/react-hook/issues",
@@ -126,9 +126,7 @@
126126
"react-test-renderer": "latest",
127127
"typescript": "latest"
128128
},
129-
"dependencies": {
130-
"@react-hook/passive-layout-effect": "^1.2.0"
131-
},
129+
"dependencies": {},
132130
"peerDependencies": {
133131
"react": ">=16.8"
134132
}

packages/event/src/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react'
2-
import useLayoutEffect from '@react-hook/passive-layout-effect'
32

43
function useEvent<
54
T extends Window = Window,
@@ -32,19 +31,19 @@ function useEvent(target: any, type: any, listener: any, cleanup: any): void {
3231
const storedListener = React.useRef(listener)
3332
const storedCleanup = React.useRef(cleanup)
3433

35-
useLayoutEffect(() => {
34+
React.useEffect(() => {
3635
storedListener.current = listener
3736
storedCleanup.current = cleanup
3837
})
3938

40-
useLayoutEffect(() => {
39+
React.useEffect(() => {
4140
const targetEl = target && 'current' in target ? target.current : target
4241
if (!targetEl) return
4342

4443
let didUnsubscribe = 0
4544
function listener(this: any, ...args: any[]) {
4645
if (didUnsubscribe) return
47-
storedListener.current.apply(this, args)
46+
storedListener.current(this, args)
4847
}
4948

5049
targetEl.addEventListener(type, listener)

packages/event/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,6 @@
12411241
resolved "https://registry.yarnpkg.com/@react-hook/latest/-/latest-1.0.2.tgz#767eb6974f91eef353981b8b60a87147dadecb18"
12421242
integrity sha512-zLtOIToct1EBTbwldkMJsXC2eCsmWOOP7z6UG0M/sCgnPExtIjvVMCpPESvPnMbQzDZytXVy0nvMbUuK2gZs2A==
12431243

1244-
"@react-hook/passive-layout-effect@^1.2.0":
1245-
version "1.2.0"
1246-
resolved "https://registry.yarnpkg.com/@react-hook/passive-layout-effect/-/passive-layout-effect-1.2.0.tgz#1232f0b08f9bfd9f87a2898a3ae50d5f7731d806"
1247-
integrity sha512-obGcMHoeiG/qp9djzlxwvlsAzL4a+JFaxTLvJv8GykipmS/TEkfvdcpu6orE1ZL4dAT7OpoGwHDc/LGJbkZzXQ==
1248-
12491244
"@rollup/plugin-babel@^5.0.2":
12501245
version "5.0.2"
12511246
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-5.0.2.tgz#d9351b9545b0c586a193fc99830d4b1a25317ed5"

0 commit comments

Comments
 (0)