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

87
Vistas
Using setState cause blank page

I have a parent and one child component. The parent passes setState to the child as props.

<SkillFunc handleChange={this.setState.bind(this)} />

Here's how the child uses it

props.handleChange({rating: count});

The problem is that doing this causes a blank page. Nothing renders, completely white. The error in the console is (There's nothing above.):

The above error occurred in the <SkillFunc> component:

at SkillFunc (webpack-internal:///./components/common/components/skillFunc.tsx:26:70)

In line 26,

var _React$useState = react__WEBPACK_IMPORTED_MODULE_1___default().useState({
0: true,
1: true,
2: true,
3: true,
4: true

}),

But I assume it meant this:

const [ratings, setRatings] = React.useState(
    {
        0: true,
        1: true,
        2: true,
        3: true,
        4: true
    }
);

I tried to pass {console.log} as props to SkillFunc and it worked perfectly. It only happens when I use the setState. I don't really know how to fix this. Grateful for any help.

Edit: I have solved it by putting the props.handleChange inside the function which gets called when the component state changes.

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

0

That feature is called lifting state look it here https://codesandbox.io/s/vigilant-poitras-hiv1fi

Also, you can see it on React DOCS

let me know if you got it!!

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