I'm creating a React app with some API calls. I have the following code to call an API which has an object with several keys & values and update some states with those values. But after updating states, program still show initial states instead updated values. When I put console.log inside the state call back, that console part will be missing. And then console says map is not a function in orderd.map So I guess the initial state of ordered is the problem
Component:
class Dashboard extends Component {
constructor(props) {
super(props);
this.state = {
columns: '',
ordered: 'null'
};
}
componentDidMount() {
API.get('project')
.then(({ data }) => {
this.setState({
columns: data.response,
ordered: Object.keys(data.response)
} () =>
console.log("order is ",this.state.ordered);
);
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}
render(){
return(
<div>\
{(provided) => (
<div ref={provided.innerRef} {...provided.droppableProps} className={classes.taskboard}>
{ordered.map((key, index) => (
<Column
key={key}
index={index}
title={key}
tasks={columns[key]}
getCardId={this.getPojectId}
/>
))}
</div>
)}
</div>
)
}
}
API success is working. But what I can see in console is "order is null"