Skip to content

Commit b178c10

Browse files
committed
Merge branch 'main' of github.com:Alexandrebdry/react-use-scroll-navigate
2 parents 2367e96 + ec979b7 commit b178c10

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

.gitignore

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# built files
2+
cjs/
3+
esm/
4+
15
# Logs
26
logs
37
*.log
@@ -51,8 +55,8 @@ build/Release
5155
node_modules/
5256
jspm_packages/
5357

54-
# TypeScript v1 declaration files
55-
typings/
58+
# Snowpack dependency directory (https://snowpack.dev/)
59+
web_modules/
5660

5761
# TypeScript cache
5862
*.tsbuildinfo
@@ -94,7 +98,7 @@ dist
9498

9599
# Gatsby files
96100
.cache/
97-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
101+
# Comment in the public line in if your project uses Gatsby and not Next.js
98102
# https://nextjs.org/blog/next-9-1#public-directory-support
99103
# public
100104

@@ -112,3 +116,6 @@ dist
112116

113117
# TernJS port file
114118
.tern-port
119+
120+
# Stores VSCode versions used for testing VSCode extensions
121+
.vscode-test

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class ScrollNavigateTopError extends Error {
3434
export function useScrollNavigate(path = "/", top = 0 , left = 0 ) {
3535

3636
const navigate = useNavigate();
37-
const [scrollNavigateError, setScrollNavigateError] = useState() ;
37+
const [scrollNavigateError, setScrollNavigateError] = useState(null) ;
3838
const scrollNavigate = useCallback( (path, top, left) => {
3939
if (typeof path != "string") {
4040
setScrollNavigateError(new ScrollNavigatePathError("Path is not a string")) ;
@@ -71,7 +71,7 @@ export function useScrollNavigate(path = "/", top = 0 , left = 0 ) {
7171
export const NavigateContext = createContext();
7272
export const NavigateContextProvider = ({children}) => {
7373
const navigate = useNavigate();
74-
const [navigationBeacon, setNavigationBeacon] = useState(false) ;
74+
const [navigationBeacon, setNavigationBeacon] = useState(null) ;
7575
const navigationRef = useRef() ;
7676

7777
const navigateToRef = useCallback((path) => {
@@ -81,10 +81,10 @@ export const NavigateContextProvider = ({children}) => {
8181
},[navigate, setNavigationBeacon]);
8282

8383
const value = useMemo(() => {navigationRef, navigateToRef},
84-
[navigationRef,navigateToRef()]);
84+
[navigationRef,navigateToRef]);
8585

8686
useLayoutEffect(() => {
87-
if (navigationBeacon === false )return
87+
if (navigationBeacon === false || navigationBeacon === null )return
8888
if(navigationRef.current instanceof HTMLElement) {
8989
const {left,top} = navigationRef.current.getBoundingClientRect();
9090
window.scroll({left,top,behavior:'smooth'});

0 commit comments

Comments
 (0)