Answer the question
In order to leave comments, you need to log in
How to properly process the data?
There is this code:
import React, { Component } from 'react';
import AllPositionData from "./DataPosition/AllPositionData";
import ErrorMassage from './GlobalCont/ErrorMassage';
import GlobalCont from './GlobalCont/GlobalCont';
export default class App extends Component {
AllPositionData = new AllPositionData();
state = {
pos: {},
peoples: {},
error: true
}
componentDidMount() {
this.updataPos()
this.updataPeoples()
// setInterval(() => this.updata(), 5000);
}
updataPos() {
this.AllPositionData.getResourcePos()
.then(this.onDataLoadedPos)
.catch(this.onError);
}
updataPeoples() {
this.AllPositionData.getResourcePeoples()
.then(this.onDataLoadedPeoples)
.catch(this.onError);
}
onDataLoadedPos = (pos) => {
this.setState({
pos,
error: false
});
}
onDataLoadedPeoples = (peoples) => {
this.setState({
peoples,
error: false
});
}
onError = () => {
this.setState({
error: true
})
}
render() {
const { error } = this.state;
if (error) {
return <ErrorMassage />
}
return (
<GlobalCont datapos={this.state} />
)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question