Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Return the same value for every first 3 items

I'm trying to return the same value for every 3 items inside of a function. I'm doing this to align images in rows of cards by giving a certain height to each row of 3 each 3 card would have the same height than the next three will have the same etc.

  const handleHeadline = (): string => {
    const lineHeight: number = parseInt(headlineRef.current?.style?.lineHeight, 10)
    const lineBreaks = headlineRef.current?.offsetHeight / lineHeight

    if (lineBreaks === 1) {
      return '40px'
    }
    if (lineBreaks === 2) {
      return '60px'
    }
    if (lineBreaks === 3) {
      return '80px'
    }
    if (lineBreaks === 4) {
      return '100px'
    }
    return ''
  }

This function runs inside of the mapped row of cards. The maps run through up to 3 items for each row.

    {rows.slice(0, rowCount || rows.length).map((row, i) => (
        <OuterContainer key={uuidv4()}>
          <Container>
            {row.map(
              (card: OpenGraphCardProp, idx: number) =>
                (card?.headline || card?.image) && (
                  <OpenGraphCard
                    id={idx + 1 || card.id}
                    headline={card.headline}
                    image={card.image}
                    subline={card.subline}
                    name={card.name}
                    link={card.link}
                    key={`${card.id}-${uuidv4()}`}
                    linkText={card.linkText}
                    baseUrl={baseUrl}
                  />
                )
            )}
          </Container>
          {i < rows.length - 1 ? (
            <DividerContainer>
              <Divider />
            </DividerContainer>
          ) : null}
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!