Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda