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

89
Vistas
deleting mapStateToProps will give undefined

I am React beginner, trying to convert class to hooks, need an advice/help on how to safely remove 'mapStateToProps ' without getting undefined.

i have page A.js and page B.js.

Component B.js i have posted whole code here so it is simple to understand. At the moment console log will give me an array of objects.

If i remove 'mapStateToProps ' and set connect(null, null)(ConnectedList)

then console log will give me 'undefined'.

This is my A.js where i'm using component B.js:

    <React.Fragment>
                <h3>
                  <Trans i18nKey="home.brokers">Brokers</Trans>
                </h3>
                <B action="brokers" actionArgs={site.identifier} />
                <h3>
                  <Trans i18nKey="home.cameras">Cameras</Trans>
                </h3>
                <B action="cameras" actionArgs={site.identifier} />
              </React.Fragment>

this is my B.js which i want to convert and get rid of 'mapStateToProps '

import React, { Component, useEffect, useState } from "react";
import { connect, useDispatch } from "react-redux";
const mapStateToProps = (state) => ({
  sites: state.articles.sites,
  analysers: state.siteArticles.analysers,
  brokers: state.siteArticles.brokers,
  cameras: state.siteArticles.cameras,
  platforms: state.siteArticles.platforms,
});

function ConnectedList(props) {
  console.log("data", props[props.action]);

  return <div></div>;
}

const B= connect(mapStateToProps, null)(ConnectedList);

export default B;

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

0

I suggest that you use useSelector hook from react-redux to solve this problem.

As you can define any logic in your callback in useSelector you can easily extract the part of the state you need from props.action. If you want you can even lift this logic into a separate selector function then add it to your useSelector parameter.

export default function ConnectedList(props) {
  const data = useSelector((state) => {
    const articles = {
      sites: state.articles.sites,
      analysers: state.siteArticles.analysers,
      brokers: state.siteArticles.brokers,
      cameras: state.siteArticles.cameras,
      platforms: state.siteArticles.platforms,
    };

    return articles[props.action];
  });

  return <div></div>;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

We connect a Component to the Redux when we want to read or change a value.

Otherwise, there is no need for Redux.

Just skip it

export default Component
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