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

docs(start/framework/route-module): add props example to Component section #12838

Merged
merged 16 commits into from
Jan 26, 2025

Conversation

Sanjai451
Copy link
Contributor

@Sanjai451 Sanjai451 commented Jan 23, 2025

This PR improves the docs by adding clear instructions on how to retrieve props in React Router v7. It also covers how to use useLocation, useNavigate, and useParams hooks within route components for better data management and navigation.

Closes #12831

Copy link

changeset-bot bot commented Jan 23, 2025

⚠️ No Changeset found

Latest commit: 4a2a5ab

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jan 23, 2025

Hi @Sanjai451,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Jan 23, 2025

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@brookslybrand
Copy link
Contributor

Thanks @Sanjai451 for helping identify places where the docs could be better. A few notes:

  1. Please remove the .changeset/kind-pears-exist.md file. Changes to the docs don't need a changeset
  2. Not sure if it was a typo, but you said "how to retrieve props in React Router v6". We are on React Router v7 now
  3. The example you gave isn't using props, it's using hooks

I think we can just update the code example to be something like this:

export default function MyRouteComponent({ loaderData, actionData, params, matches }) {
  return (
    <div>
      <h1>Look ma!</h1>
      <p>
        I'm still using React Router after like 10 years.
      </p>
    </div>
  );
}

This doc is meant to be a pretty simple reference, and more details about the different hooks available can be found in the api reference.

We plan to add more docs around using these hooks, but this is not the place we want to document them

@@ -135,6 +135,7 @@ export async function clientLoader({
params,
}: Route.ClientLoaderArgs) {
const res = await fetch(`/api/products/${params.pid}`);
const serverData = await serverLoader({ params });
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think serverLoader takes any args

docs/start/framework/route-module.md Outdated Show resolved Hide resolved
```

### Benefits of using props
1. Route data is directly accessible via props, leading to more readable code.
Copy link
Contributor

Choose a reason for hiding this comment

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

Another benefit is Route data can be automatically typed if you follow the instructions and import the Route from the +types

@Sanjai451 Sanjai451 requested a review from davidbielik January 26, 2025 16:28
@Sanjai451 Sanjai451 requested a review from davidbielik January 26, 2025 16:42
@timdorr
Copy link
Member

timdorr commented Jan 26, 2025

Thanks!

@timdorr timdorr merged commit 6af0ad5 into remix-run:main Jan 26, 2025
1 check passed
@MichaelDeBoey MichaelDeBoey changed the title Updated Documentation with examples using props docs(start/framework/route-module): add props example to Component section Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Docs]: Document Route.ComponentProps
5 participants