title: React - getDerivedStateFromProps and axios
body: <p>I would like to set state variable <code>books</code> as result of API. I cannot do it in <code>componentDidMount</code>, because I don't have token at the beginning and need it to get result from API. Nothing happens with state <code>books</code> when I run following code. If I put <code>state.books=res.data</code> before return I got a result, but after manually refresh page.</p>
  
  <pre><code>constructor(props) {
          super(props);
          this.state = {
              books: [],
          };
      }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>static getDerivedStateFromProps(nextProps, state) {
          if (nextProps.token){
              axios.defaults.headers = {
                  "Content-Type": "application/json",
                  Authorization: "Token " + nextProps.token
              }
              axios.get('http://127.0.0.1:8000/api/book/own/')
                  .then(res =&gt; {
                      return {
                          books: res.data,
                      }  
                  }) 
         }
  </code></pre>
  
  <p>data from the API looks like:</p>
  
  <pre><code>{
    id: 66,
    isbn: "9780545010221",
    title: "Title",
    author: "Author,Author",
  }
  </code></pre>
  
  <p>In the render method I call component with <code>this.static.books</code> data. </p>
  
  <p>Could you please advise me?</p>