Skip to content

Commit ec979b7

Browse files
committed
update scroll to ref
1 parent 34f9998 commit ec979b7

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
@@ -47,8 +51,8 @@ build/Release
4751
node_modules/
4852
jspm_packages/
4953

50-
# TypeScript v1 declaration files
51-
typings/
54+
# Snowpack dependency directory (https://snowpack.dev/)
55+
web_modules/
5256

5357
# TypeScript cache
5458
*.tsbuildinfo
@@ -90,7 +94,7 @@ dist
9094

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

@@ -108,3 +112,6 @@ dist
108112

109113
# TernJS port file
110114
.tern-port
115+
116+
# Stores VSCode versions used for testing VSCode extensions
117+
.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)