Skip to content

Commit

Permalink
fix: render the mdx scroll button after react hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
jeangovil committed Jul 18, 2023
1 parent 3f4edb4 commit ad03d46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import clsx from 'clsx'
import React, { PropsWithChildren } from 'react'
import { useHydrated } from '../../../lib/useHydrated'
import { useHero } from '../Hero/Hero.context'
import { ScrollToBottom } from '../index'
import './HeroInfo.scss'
Expand All @@ -17,6 +18,7 @@ export const HeroInfo: React.FC<HeroInfoProps> = ({
...props
}) => {
const ctx = useHero()
const hydrated = useHydrated()
const size = sizeProp ? sizeProp : ctx ? ctx.size : 'medium'

return (
Expand All @@ -27,7 +29,7 @@ export const HeroInfo: React.FC<HeroInfoProps> = ({
>
{children}
</div>
<ScrollToBottom />
{hydrated && <ScrollToBottom />}
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import clsx from 'clsx'
import React, { HTMLProps } from 'react'
import { useWindowSize } from 'react-use'
import { makeStyle } from '../../../lib/makeStyle'
import { useHydrated } from '../../../lib/useHydrated'
import { useIsMobile } from '../../../lib/useIsMobile'
import { useScrollY } from '../../../lib/useScrollY'
import styles from './styles.module.scss'
Expand All @@ -14,7 +13,6 @@ export const ScrollToBottom = (
props: TProps & HTMLProps<HTMLButtonElement>,
): JSX.Element => {
const { children, className, style, ...rest } = props
const isHydrated = useHydrated()
const scrollY = useScrollY()
const isMobile = useIsMobile()
const ws = useWindowSize()
Expand Down Expand Up @@ -43,7 +41,7 @@ export const ScrollToBottom = (
className={clsx(
styles.scrollToBottom,
className,
(scrollY > 20 || !isHydrated) && styles.hide,
scrollY > 20 && styles.hide,
)}
style={makeStyle({ ...(style ?? {}) }, { vh: ws.height / 100 + 'px' })}
{...(rest as any)}
Expand Down

0 comments on commit ad03d46

Please sign in to comment.