title: Proper way to get URL params on React component mount?
body: <p>I have a component for which I want to get URL params (say, a1 and a2). If these contain anything, I want to set some local state to their values so things can be rendered on the page. I'm using <code>react-router-dom</code> and the <code>withRouter</code> HOC, so I can access <code>location</code> from <code>props</code>, but I'm not sure if I can use that. Right now I have:</p>
  
  <pre><code>class Example extends Component {
      constructor(props) {
      super(props);
  
      this.state = {
        a1: null,
        a2: null,
      }
    }
  
    componentDidMount() {
      console.log(window.location.search);
      const parsed = querystring(window.location.search);
      this.setState({
        a1: parsed.a1,
        a2: parsed.a2,
      })
    }
  }
  </code></pre>
  
  <p>Now, doing this gives me an ESLint warning for <code>Do not use SetState in ComponentDidMount</code>. I've done some searching and that's apparently 'ok' to do in a callback from <code>componentDidMount</code>, but this isn't a callback, so I'm not sure if it's 'ok'.</p>
  
  <p>So what's the right thing to do here? Do I ignore the warning (and get the double-render)? Is there some other way to properly get URL params and set them to local state?</p>
  
  <p>I also don't want to use any methods that will be deprecated in React 17, since that just means re-writing it on upgrade...</p>