V
V
Vyacheslav Shabunin2021-08-12 14:29:56
React
Vyacheslav Shabunin, 2021-08-12 14:29:56

What are the reasons setState does not change the state?

This function, for unknown reasons, does not change the state. Tried to use other state functions, also used regular class functions. But the state of the application still does not change.
What could be causing this?

import React from "react";
import '../CSS/CaseContainers.css';

export default class Winners extends React.Component{
    constructor(props) {
        super(props);

        this.state = {
            answer: [],
            login: null
        };
    }   
    async componentDidMount(){
        await fetch(this.props.conf + "connect/winlist", {
            method: "get"
        }).then(response => {return response.json()})
        .then(response => console.log(response))
        .then(response => this.setState({answer: response}));
    }
    render(){
        console.log("outFetch");
        console.log(this.state.answer);
        return(
            <div className="Winners">
              <h3>{}</h3>
            </div>
        );
    }
}

611505fb17849344008196.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2021-08-12
@fleshherbal

Take away: The call to console.log returns undefined, which is passed on to setState.
.then(response => console.log(response))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question