Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rework how sync state is handled
This simplifies the sync store for navigation state: - Use a external store to store the state instead of `useState` - so the store can be updated synchronously - Use `useSyncExternalStore` API to subscribe to the state changes - Use an effect when a child navigator needs to update state due to list of screens changing etc. The changes should make the code easier to understand, as well as should make the code compatible with concurrent mode as we're not doing anything weird with the state.
- Loading branch information
Showing
8 changed files
with
155 additions
and
161 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,3 @@ | ||
import { useLayoutEffect } from 'react'; | ||
|
||
export const useIsomorphicLayoutEffect = useLayoutEffect; |
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,7 @@ | ||
import { useEffect, useLayoutEffect } from 'react'; | ||
|
||
/** | ||
* Use `useEffect` during SSR and `useLayoutEffect` in the browser to avoid warnings. | ||
*/ | ||
export const useIsomorphicLayoutEffect = | ||
typeof document !== 'undefined' ? useLayoutEffect : useEffect; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.