Skip to content

Commit 380e900

Browse files
committed
main 🧊 add default window for scrolls
1 parent 2bd2623 commit 380e900

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

‎packages/core/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@siberiacancode/reactuse",
3-
"version": "0.2.30",
3+
"version": "0.2.31",
44
"description": "The ultimate collection of react hooks",
55
"author": {
66
"name": "SIBERIA CAN CODE 🧊",

‎packages/core/src/bundle/hooks/useScrollIntoView/useScrollIntoView.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useEffect, useRef } from 'react';
1+
import { useRef } from 'react';
22
import { getElement, isTarget } from '@/utils/helpers';
3+
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';
34
import { useRefState } from '../useRefState/useRefState';
45
/**
56
* @name useScrollIntoView
@@ -40,7 +41,7 @@ export const useScrollIntoView = (...params) => {
4041
immediately = true
4142
} = options ?? {};
4243
const elementRef = useRef(null);
43-
useEffect(() => {
44+
useIsomorphicLayoutEffect(() => {
4445
if (!immediately) return;
4546
if (!target && !internalRef.state) return;
4647
const element = (target ? getElement(target) : internalRef.current) ?? window;

‎packages/core/src/hooks/useScrollIntoView/useScrollIntoView.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { useEffect, useRef } from 'react';
1+
import { useRef } from 'react';
22

33
import type { HookTarget } from '@/utils/helpers';
44

55
import { getElement, isTarget } from '@/utils/helpers';
66

77
import type { StateRef } from '../useRefState/useRefState';
88

9+
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';
910
import { useRefState } from '../useRefState/useRefState';
1011

1112
/** The scroll into view options type */
@@ -74,7 +75,7 @@ export const useScrollIntoView = ((...params: any[]) => {
7475
} = options ?? {};
7576
const elementRef = useRef<Element>(null);
7677

77-
useEffect(() => {
78+
useIsomorphicLayoutEffect(() => {
7879
if (!immediately) return;
7980
if (!target && !internalRef.state) return;
8081

‎packages/core/src/hooks/useScrollTo/useScrollTo.demo.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { useScrollTo } from '@siberiacancode/reactuse';
22

33
const Demo = () => {
4-
const scrollTo = useScrollTo<HTMLDivElement>({ x: 0, y: 260 });
4+
const scrollTo = useScrollTo<HTMLDivElement>({
5+
x: 0,
6+
y: 260,
7+
behavior: 'smooth'
8+
});
59

610
return (
711
<div>

0 commit comments

Comments
 (0)