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

134
Vistas
Reescriba un mapStateToProps para un useSelector

Me disculpo de antemano, mi inglés es malo. Estoy tomando un curso sobre reaccionar y quiero reescribir este componente para usar Selector, pero no puedo. Uno de los accesorios está destinado a ser indefinido. Quien me puede explicar como hacer esto? También estoy usando la biblioteca "Volver a seleccionar"

Código:

 import React from "react"; import { connect } from "react-redux"; import CollectionItem from "../../components/CollectionItem/CollectionItem"; import "./CollectionPage.scss"; import { selectCollection } from "../../redux/shop/shop.selectors"; const CollectionPage = ({ collection }) => { console.log(collection); return ( <div className="collection-page"> <h2>COLLECTION PAGE</h2> </div> ); }; const mapStateToProps = (state, ownProps) => ({ collection: selectCollection(ownProps.match.params.collectionId)(state), }); export default connect(mapStateToProps)(CollectionPage);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Los selectores parametrizados se explican con más detalle aquí

Su código podría verse algo así:

 //method to get all collections const selectCollections = (state) => state.collections; //method to create a selector that gets a selection by id const createSelectCollectionById = (collectionId) => createSelector( [selectCollections], //all collections (collections) => //just guessing the logic to get collection by id collections.find(({ id }) => id === collectionId) ); //use react memo to crate a memoized component const CollectionPage = React.memo(function CollectionPage( props ) { //collection id to create dependency for useMemo const collectionId = props.match.params.collectionId; //crate selector for this collection id const selectCollectionById = React.useMemo( () => createSelectCollectionById(collectionId), [collectionId] ); //use the selector to get the collection item const collection = useSelector(selectCollectionById); console.log(collection); return ( <div className="collection-page"> <h2>COLLECTION PAGE</h2> </div> ); });
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