K
K
Kentavr162021-05-29 18:07:35
React
Kentavr16, 2021-05-29 18:07:35

How to display the values ​​received from the server in React?

Good day. Cannot use server response.

import React from 'react'
import axios from "axios"

class NewTask extends React.Component{
    constructor(props) {
        super(props);
        this.state = {
          isLoading: true,
          description: null,
          task: null,
    };
    }

    async componentDidMount() {
        try {axios.get('http://localhost:5000/api/getTask')
        .then((response)=>{this.setState({description: response.data.description})})
    }
        catch( error ) {
            console.log(error);
        };  }
    
    render() {
        var { isLoading, description, task} = this.state;


        
    

    return(
        <div className="createTaskWrap">
            <p>Здесь ты можешь создать новый таск:</p>
            <div className="desP"><p>{this.state.description}</p></div>

        </div>
    )
}


}

export default NewTask


initially I wanted to display the values ​​received from the server in the application state in order to work with them further. But - this answer does not work out somehow. The response type is application json, there are only two values. I checked in the developer console - the correct json is coming.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kentavr16, 2021-05-29
@Kentavr16

The answer turned out to be the following: you need to process the whole thing as an object. Sat all day, started to blunt.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question