I want to do something like this (doesn't work, obviously)
I could store the result in a state and have the component be rendered in the render()
method, but the problem with that is I am making many calls and will have many res objects.I will end up with a lot of states to maintain, so I want to just return a component after axios
calls instead of changing the many states every time. Is this possible?
class InstanceViewer extends React.Component {
constructor(props) {
super(props);
this.MyComponent = {}
}
componentWillMount() {
getData()
}
getData(){
axios.get('/myurl/', {})
.then((res) => {
this.MyComponent = <h1> res </h1>
});
}
// I just put this line there because I don't know the correct way to do this
render(){return({this.MyComponent})}
}