Skip to content

Commit

Permalink
feat(react-dom): add inViewOptions as FadeInProps
Browse files Browse the repository at this point in the history
  • Loading branch information
manudeli committed Nov 19, 2024
1 parent 1e1238f commit c581697
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/visualization/src/app/react-dom/FadeIn/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function Page() {
key={userId}
clientOnly
fallback={
<FadeIn delay={200} duration={1000}>
<FadeIn delay={200} duration={1000} inViewOptions={{ triggerOnce: true }}>
{skeleton}
</FadeIn>
}
Expand Down
6 changes: 4 additions & 2 deletions packages/react-dom/src/FadeIn.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type CSSProperties, type ComponentPropsWithoutRef, type ElementType } from 'react'
import { useInView } from './useInView'
import { type InViewOptions, useInView } from './useInView'

type FadeInProps<TAs extends ElementType> = ComponentPropsWithoutRef<TAs> & {
/**
Expand All @@ -18,17 +18,19 @@ type FadeInProps<TAs extends ElementType> = ComponentPropsWithoutRef<TAs> & {
* The timing function of the animation.
*/
timingFunction?: CSSProperties['animationTimingFunction']
inViewOptions?: InViewOptions
}

export function FadeIn<TAs extends ElementType = 'div'>({
as,
delay = 0,
duration = 200,
timingFunction = 'linear',
inViewOptions,
...rest
}: FadeInProps<TAs>) {
const Component = as ?? 'div'
const { inView, ref } = useInView()
const { inView, ref } = useInView(inViewOptions)
return (
<Component
{...rest}
Expand Down

0 comments on commit c581697

Please sign in to comment.