Yes, so you can write a React component in one of two ways: as a functional component (the "newer" way), and as a class component.
You could convert your class component to a functional component:
const IndexPage = (pageProps) => { const { search } = window.location; const query = new URLSearchParams(search).get('s'); const [searchQuery, setSearchQuery] = useState(query || ''); } export default IndexPage;
And that would let you use the useState hook. You can still use class components, but I think it makes things a little bit more complicated :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yes, so you can write a React component in one of two ways: as a functional component (the "newer" way), and as a class component.
You could convert your class component to a functional component:
And that would let you use the useState hook. You can still use class components, but I think it makes things a little bit more complicated :)