Skip to content

Commit

Permalink
Switch from useElementSize to useResizeObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Feb 22, 2024
1 parent ec5bd68 commit fa5dab7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/routes/_gcn.user.endorsements/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
useRef,
useState,
} from 'react'
import { useElementSize } from 'usehooks-ts'
import { useResizeObserver } from 'usehooks-ts'

import { formatAuthor } from '../_gcn.circulars/circulars.lib'
import type {
Expand Down Expand Up @@ -232,8 +232,11 @@ export function EndorsementRequestCard({
const disabled = fetcher.state !== 'idle'
const [showMore, setShowMore] = useState(false)

const [noteRef, { width }] = useElementSize()
const [noteContainerRef, { width: containerWidth }] = useElementSize()
const noteRef = useRef<HTMLSpanElement>(null)
const noteContainerRef = useRef<HTMLDivElement>(null)

const { width } = useResizeObserver({ ref: noteRef })
const { width: containerWidth } = useResizeObserver({ ref: noteContainerRef })

return (
<fetcher.Form method="POST">
Expand All @@ -246,7 +249,10 @@ export function EndorsementRequestCard({
{endorsementRequest.note && (
<div className="margin-top-0 margin-bottom-1">
Comments from the user:
{(width > containerWidth || showMore) && (
{((width !== undefined &&
containerWidth !== undefined &&
width > containerWidth) ||
showMore) && (
<Button
type="button"
unstyled
Expand Down

0 comments on commit fa5dab7

Please sign in to comment.