K
K
konstantinst132020-07-26 21:20:00
React
konstantinst13, 2020-07-26 21:20:00

How to assign another array to an array in setState?

I need to assign a value to the list array in state equal to the result array. And it turns out for some reason an empty array.

import React, {Component} from 'react';
class Modal extends Component{
       constructor(props){
       super(props);
       this.state={
             list: []
           }
       }
       componentDidMount(){
             this.loagPageList();
       }
       loadPageList() {
               let result = ["1", "second"]
      
                this.setState({
                       list:  result
                })
                console.log("this.state.list: ");
                console.log(this.state.list);  //выдаёт пустой массив с length = 0
    }
     render(){
            return(
                 <div>1</div>
            )
     }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question