The problem of data call in react

when the getComment addComment page of the two interfaces is loaded, call getComment to put the return value of getComment into state, and then render it. At this time, I call addComment to change the return value of getComment. Do you want to call the getComment API again to update the original value of getComment in state? if you don"t need the value in state, how to update the latest value after calling addComment



state = {
    data: '',
}

getComment = () => {
    
    .....
    
    const data = 
    this.setState({
        data,
    })
}

addComment = () => {

    ....

    this.getComment()
}

add comments:
1, submit to the backend
2, and the front end only needs to go to push to enter the existing comments in the state, and the page will be re-rendered.

there is no need to render by re-going to getcomment. When submitting, ask the backend to return the set of comments submitted to you in the same format as the one returned by getcomment. Then push enters the state.

Menu