Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Explain how to change page with useNavigation #9840

Merged
merged 11 commits into from
May 16, 2024

Conversation

erwanMarmelab
Copy link
Contributor

@erwanMarmelab erwanMarmelab commented May 10, 2024

Problem

Sometimes, you’d like to pass a state when redirecting. However the redirect only accept a string.

Solution

Change the redirect and RedirectToFunction functions signature to accept a Location from react-router
Document useNavigate

Todo

- [x] Accept the right props
- [x] Add a story

  • Document it useNavigate more

@erwanMarmelab erwanMarmelab added the WIP Work In Progress label May 10, 2024
@@ -1,5 +1,6 @@
import { useCallback } from 'react';
import { useNavigate, To } from 'react-router-dom';
import { Location } from 'history';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you import the To type imported from 'react-router-dom' above? It would avoid the added dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is any state key in a To object. And in our first discussion on it your speak about this state

<ul>
<li>
<button onClick={() => redirect('/dashboard')}>
Dashboard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use types as labels for your buttons: Relative url, View name, View name with details, Location, Function

Copy link
Contributor Author

@erwanMarmelab erwanMarmelab May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea, applied 👍

@fzaninotto
Copy link
Member

fzaninotto commented May 13, 2024

Now, I'm thinking: since we offer exactly the same API as usenavigate, why would isers choose to use useredirect ? we should better document usenavigate rather than modify our API to mimic it

docs/useRedirect.md Outdated Show resolved Hide resolved
@@ -46,3 +46,28 @@ redirect(false);
```

Note that `useRedirect` allows redirection to an absolute URL outside the current React app.

## `useNavigate`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: I'd put this section in a tip but it's a personal opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Co-authored-by: adrien guernier <adrien@marmelab.com>
@fzaninotto fzaninotto changed the title Accept a To from react-router in useRedirect [Doc] Explain how to change page with useNavigation May 16, 2024
@fzaninotto fzaninotto merged commit 3cf2720 into next May 16, 2024
13 checks passed
@fzaninotto fzaninotto deleted the feat/useRedirect/to branch May 16, 2024 14:35
@fzaninotto fzaninotto added this to the 5.0.0 milestone May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants