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

235
Vistas
How to maximize composability with React higher-order functions?

I refer to this part of the official React tutorial (Convention: Maximizing Composability):

// connect is a function that returns another function
const enhance = connect(commentListSelector, commentListActions);
// The returned function is a HOC, which returns a component that is connected
// to the Redux store
const ConnectedComment = enhance(CommentList);

How should we implement the connect() function?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Conceptually HOC connect is something like this:

function connect(mapStateToProps, mapDispatchToProps) {
  return function (WrappedComponent) {
    return class extends React.Component {
      render() {
        return (
          <WrappedComponent
            {...this.props}
          />
        )
      }
    }
  }
}

How you can see, it's a function that return another function.

At first call connect get 2 arguments

const enhance = connect(commentListSelector, commentListActions);

At the second it get Component which we return in connect function

const ConnectedComment = enhance(CommentList);

But not only component, we return connect with new props which we get from redux - so it's approach how to get data from redux, look at more detailed example (if it's not enough for you, you can check link in a comment above):

function connect(mapStateToProps, mapDispatchToProps) {
  return function (WrappedComponent) {
    return class extends React.Component {
      render() {
        return (
          <WrappedComponent
            {...this.props}
            {...mapStateToProps(store.getState(), this.props)}
            {...mapDispatchToProps(store.dispatch, this.props)}
          />
        )
      }
    } 
  } 
}

For me more useful and convenient is react-hook pattern, check useSelector and useDispatch methods to get data from redux component to react. It's simplier, connect a legacy approach and can be useful only with Class components.

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