-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: initial state was reset in single subscription hooks in strict m…
…ode in dev With strict mode in development, each component is mounted, unmounted and remounted. Previously, `initialState` was set to `undefined` after the first mount because a change in the passed reference was assumed.
- Loading branch information
1 parent
83d1bc6
commit d0db2af
Showing
3 changed files
with
59 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useEffect, useRef } from "react"; | ||
|
||
export function usePrevious<T>(value: T) { | ||
const ref = useRef<T>(value); | ||
useEffect(() => { | ||
ref.current = value; | ||
}); | ||
return ref.current; | ||
} |