I am trying to create 2 requests and set variables with this.setState({}) for further changes.
This is what i got:
class App extends React.Component {
constructor() {
super();
this.state = {user: false, repository :false}
}
componentDidMount() {
axios.all([
axios.get('https://api.github.com/users/antranilan'),
axios.get('https://api.github.com/users/antranilan/repos')
])
.then(axios.spread(function (userResponse, reposResponse) {
this.setState({user : userResponse.data, repository : reposResponse.data});
});
}
render() {
return (
<div>
{this.state.user.login}
{this.state.repository.length}
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="app"></div>
I looked up through multiple questions with what i am trying to do but there was no solution to what i am trying to achive.
.then(axios.spreadthat looks wrong, because.thentraditionally expects a function as an argument, not the result of calling a functionaxios.allandaxios.spreadhelpers might be removed in future versions because there is native analog supported by major envs.