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

Use useLocation hook instead of relying on injected location in route components #4240

Merged
merged 5 commits into from
Jan 6, 2020

Conversation

CarsonF
Copy link
Contributor

@CarsonF CarsonF commented Jan 3, 2020

Update remaining places where location is passed in to ignore/handle it but use useLocation hook instead.

Copy link
Collaborator

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Thanks :) Note that these props will still be injected by react-router though

@djhi djhi added this to the 3.1.2 milestone Jan 6, 2020
@fzaninotto
Copy link
Member

Why should we use useLocation in components that are children of Route and therefore receive the location prop?

@fzaninotto fzaninotto removed this from the 3.1.2 milestone Jan 6, 2020
@CarsonF
Copy link
Contributor Author

CarsonF commented Jan 6, 2020

react-router is moving away from that API with the v5.1 release. It's stated that the component and render props on Route will go away with the v6 release. They expect you to use the hooks instead of them cloning the element to inject props.
https://reacttraining.com/blog/react-router-v5-1/

Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

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

OK, I understand better now, thanks.

Can you make these final tweaks?

packages/ra-core/src/controller/useCreateController.ts Outdated Show resolved Hide resolved
packages/ra-core/src/controller/useListController.ts Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/list/List.js Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/layout/NotFound.js Outdated Show resolved Hide resolved
@fzaninotto fzaninotto merged commit 3331f2c into marmelab:master Jan 6, 2020
@fzaninotto
Copy link
Member

Thanks!

@CarsonF CarsonF deleted the use-location branch January 6, 2020 16:56
@fzaninotto fzaninotto added this to the 3.1.2 milestone Jan 6, 2020
@fzaninotto fzaninotto changed the title Remove required location property Use useLocation hook instead of relying on injected location in route components Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants