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
useSelectedLayoutSegment(s) hooks both return no data #43279
Comments
|
This is definitely a regression since in precedent versions it worked, as a workaround for now you can use |
This is expected, as of #42299 From the documentation:
See: https://beta.nextjs.org/docs/api-reference/use-selected-layout-segment |
I think in the repro link, the component is marked as client component and yet the values aren't displayed. The same happens in my project where a client component doesn't log the output of |
@abhilashlr7 , what is said in the docs is that this hook has these constraints :
You can see more in the docs : https://beta.nextjs.org/docs/api-reference/use-selected-layout-segment#examples |
Agreed. This issue was less of a bug & more about (my) confusion in understanding layout segments when reading the docs & struggling to see / understand the constraints in which you can actually access layout segments. I agree & like the idea @Fredkiss3 has shared above in making it clear & obvious with some kind of callout section pointing out a (common) pitfall when using a certain feature. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
Microsoft Edge Version 107.0.1418.56 (Official build) (arm64)
How are you deploying your application? (if relevant)
N/A
Describe the Bug
Currently when trying to use either useSelectedLayoutSegment or useSelectedLayoutSegments hooks they both return no data.
useSelectedLayoutSegment
returnsnull
at all timesuseSelectedLayoutSegment
returns an empty arrayExpected Behavior
According to the docs they should be returning both either
string | null
&Array<string>
respectivelyLink to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster
https://stackblitz.com/edit/nextjs-zbazdc?file=app/(app)/[slug]/layout.tsx
To Reproduce
Follow (beta) Next.js documentation on how to use the hooks, primarily via creating a segment of any kind, & attempt to use the hooks in a client component or layout respectively.
The text was updated successfully, but these errors were encountered: