Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

85
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda