If I remember correctly, return on its own infers a return type of void, whereas return null is an acceptable React.ReactNode return type, as far as TypeScript is concerned.
And void in turn results in undefined on the caller, which React now supports, but I would still discourage. The reason support for it was added was, in part, inconsistency between nested and root-level conditional rendering.
Why not just
return
instead ofreturn null
?If I remember correctly,
return
on its own infers a return type ofvoid
, whereasreturn null
is an acceptableReact.ReactNode
return type, as far as TypeScript is concerned.And void in turn results in undefined on the caller, which React now supports, but I would still discourage. The reason support for it was added was, in part, inconsistency between nested and root-level conditional rendering.
Yes, you can definitely do that as we know whenever JavaScript sees the
return
keyword, it immediately exits the function.