Skip to content

Commit

Permalink
add dynamic import for hook too
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasSestak committed Aug 26, 2023
1 parent e07d429 commit 31cd73b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "framer-motion-scroll-to-hook-example",
"homepage": "https://TomasSestak.github.io/framer-motion-scroll-to-hook",
"version": "2.0.4",
"version": "2.0.6",
"license": "MIT",
"private": true,
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "framer-motion-scroll-to-hook",
"version": "2.0.5",
"version": "2.0.6",
"description": "useScrollToHook for Framer Motion animation library",
"author": "TomasSestak",
"license": "MIT",
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {animate, Spring, Tween} from 'framer-motion';
import {Spring, Tween} from 'framer-motion';

export const useScrollTo = (transition?: Spring | Tween) => {
let isStopped = false;
Expand All @@ -8,7 +8,7 @@ export const useScrollTo = (transition?: Spring | Tween) => {
window.removeEventListener('wheel', onWheel);
};

const scrollTo = (target?: Element | number | string | null, offset: number = 0) => {
const scrollTo = async (target?: Element | number | string | null, offset: number = 0) => {
let y = 0;

if (typeof target === 'number') {
Expand All @@ -27,6 +27,7 @@ export const useScrollTo = (transition?: Spring | Tween) => {
y += offset;

window.addEventListener('wheel', onWheel);
const {animate} = await import('framer-motion');
animate(window.scrollY, y, {
...transition,
onComplete: () => {
Expand All @@ -53,7 +54,7 @@ interface ScrollToProps {
}


export const scrollTo = async ({ scroller = window, transition, target, offset = 0 }: ScrollToProps | undefined = {}) => {
export const scrollTo = async ({scroller = window, transition, target, offset = 0}: ScrollToProps | undefined = {}) => {
if (typeof window === 'undefined' || !scroller) {
return;
}
Expand Down Expand Up @@ -86,7 +87,7 @@ export const scrollTo = async ({ scroller = window, transition, target, offset =
y += offset;

scroller.addEventListener('wheel', onWheel);
const { animate } = await import('framer-motion');
const {animate} = await import('framer-motion');
animate(scrollY, y, {
...transition,
onComplete: () => {
Expand Down

0 comments on commit 31cd73b

Please sign in to comment.