next.js
e5b6e2e8 - docs: update `useParams` hook return statement (#67384)

Commit
1 year ago
docs: update `useParams` hook return statement (#67384) Hi 👋🏻 ## The Change I noticed that in one example of the [`useParams` hook](https://nextjs.org/docs/app/api-reference/functions/use-params), there is an old-fashioned return statement that returns a react fragment instead of null. This step was part of the workaround from the typescript environment from 2016, which is now obsolete. Recently, I researched why some people do it today and whether we should continue doing it in a react environment. I created a document discussing it: https://github.com/Kuboczoch/web-dev-best-practices/blob/master/react/conditional-rendering_return-react-fragment.md tl;dr > While returning a `React.Fragment` instead of `null` in a React component was a workaround for TypeScript limitations in 2016, this is no longer necessary. Returning `null` is more efficient, makes the code more readable, is officially supported, and aligns with current best practices. ## Why? It helps to provide the best practice to other developers who are just starting with web development and are mindlessly copy-pasting the code. In this case, people do not need to research workarounds for TypeScript from six years ago. --------- Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
Author
Parents
Loading