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

106
Visualizações
Page does not reload on state change inside jsx

I have seen several questions with the same title but not the same problem,

I wrote some react code and inside return method's jsx, inside select onchange I called a function that setstate but the page will not reload although I made sure the state is changed

jsx code inside return:

<select defaultValue={book.shelf} onChange={(e) => this.handleChange(e, book)}

code inside contructor

constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);}

code inside component

 handleChange = (e, book) => {
 BooksAPI.update(book, e.target.value).then(this.setState(
     { value: e.target.value, book: book },
     () => console.log(this.state.value)
   ));

};

Knowing that this.state.value prints correctly and the value is returned from the API and it is different from the previous state's value

What could be the problem,

Any help appreciated.

Edit: My full select code

<select defaultValue={book.shelf} onChange={(e) => handleChange(e, book)}>
                        <option value="move" disabled>
                          Move to...
                        </option>
                        <option value="currentlyReading">
                          Currently Reading
                        </option>
                        <option value="wantToRead">Want to Read</option>
                        <option value="read">Read</option>
                        <option value="none">None</option>
                      </select>

Edit 2:

This is my state

 state = {
    books: [],
    value: '',
    book: {},
    update: false,
  };

Final edit:

To prevent confusion the problem was with my UI unrelated to this code

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem is this

handleChange = (e, book) => {
 BooksAPI.update(book, e.target.value).then(this.setState(
     { value: e.target.value, book: book },
     () => console.log(this.state.value)
   ));

Change it to this

handleChange = (e, book) => {
 BooksAPI.update(book, e.target.value).then(() => {
    this.setState(
     { value: e.target.value, book: book },
     () => console.log(this.state.value)
   )
 });
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