From ad1bcdf20f04bca25c2f1fb10bdec6dc746a3bfe Mon Sep 17 00:00:00 2001 From: Manmohanjit Singh <7972390+manmohanjit@users.noreply.github.com> Date: Fri, 16 Aug 2024 01:41:37 +0800 Subject: [PATCH] Update index.ts to use useLayoutEffect --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index e14808b..d2e9001 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useLayoutEffect } from "react"; import throttle from "lodash/fp/throttle"; export interface useScrollSpyParams { @@ -35,7 +35,7 @@ export default ({ setActiveSection(currentSectionId); }); - useEffect(() => { + useLayoutEffect(() => { const scrollable = scrollingElement?.current ?? window; scrollable.addEventListener("scroll", handle);