Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
React renderProps in functional components: how to replace?

I haven't had to write a renderProps pattern since functional components/hooks became the thing to do - until now. Upon googling if its still the right approach, i've read a few articles on renderProps being old news and an antipattern. Alternatives provided include hooks or passing in a JSX node.

However, I have a requirement that can't be used by these two. I need to:

  • Use a prop passed in from the child component.
  • Use a prop within the parent component that is not used by the child.

It looks a bit like this:

const parent = (parentProp) => {
   const actions = useCallback((childProps) => {
     return <Button p1={childProps} p2={parentProps} />
   }, [parentProp])

   return <Child renderActions={actions} />
}

const child = (renderActions) => {
  const [childProp] = useState(1)

  const actionRenderer = useCallback(() => {
    return renderActions(childProp)
  }, [childProp, renderActions)
  
  return (
    <div>{actionRenderer}</div>
  )
}

I am concerned about performance and unnecessary re-renders, so the usecallbacks should stop this.

Is there a more 'modern' way of achieving this functionality or is renderProps still viable?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I don't see a problem with your code honestly (apart from several typos).

Render Props pattern is still viable as are hooks and HOC.

Read this if you want to learn more: https://stackoverflow.com/a/58856111/3930247

Personally, I almost never use render props because it makes the code less readable but that's just my opinion. There are many examples where render props are used in modern React.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda