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

136
Vistas
react js variable update delay - react.js

Using React.js,, I am trying to filter projects table by project size, but there is a problem the state is always one step back

Here is my filtering element

here is my handler method

 handleProjectSize = (projectSize) => {
this.setState({ selectedProjectSize: projectSize });
console.log('selected: ', this.state.selectedProjectSize);
console.log('clicked: ', projectSize);
console.log('-----------------------------------------');

};

and here is a condition for filtering the projects if I click on a filter - in the render method

const filterdProjects = this.selectedProjectSize
  ? projects.filter((ps) => ps.projectSize._id === selectedProjectSize._id)
  : projects;

and here is my element

 <ul className='list-group'>
          {projectSizes.map((projectSize) => (
            <li
              className='list-group-item'
              key={projectSize._id}
              onClick={() => this.handleProjectSize(projectSize)}
            >
              {projectSize.name}
            </li>
          ))}
        </ul>

Important Note: All this code is in one component

in this screenshot you can see the values on console when I pressed all projects still the selected variable is undefined and then when I click the major, the selected is still all project... and that means there is one step delay

and here is my console when I press on any filter there is always delay

about 4 years ago · Juan Pablo Isaza
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