I noticed that in one example of the useParams hook, 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.
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.
Hi ππ»
The Change
I noticed that in one example of the
useParams
hook, 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
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.