pbeshai / use-query-params

React Hook for managing state in URL query parameters with easy serialization.
https://pbeshai.github.io/use-query-params
ISC License
2.13k stars 95 forks source link

Enqueue premature calls to useNavigate() in react-router-6 adapter #266

Open afn opened 1 year ago

afn commented 1 year ago

Prevent premature calls to useNavigate() from failing with "You should call navigate() in a React.useEffect(), not when your component is first rendered".

This warning happens even when navigate() is called from a useEffect(), because that effect is called before useNavigate's internal effect (parents' effects are invoked after children's effects).

To get around this, enqueue premature useNavigate() calls, and process the queue in a useEffect() (which is called after useNavigate's effect).

Fixes #211.