is icon indicating copy to clipboard operation
is copied to clipboard

Add is.renderInReact or is.notRenderInReact

Open tychenjiajun opened this issue 3 years ago • 1 comments

https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored

Only certain types in React can be rendered. false, null, undefined, and true are valid React children. They don’t render.

Here, I propose a new API and its use case:

<div>{is.renderInReact(foo) ? foo : EMPTY_VALUE}</div>

Since renderInReact might requires @types/react, notRenderInReact may be better. It's equal to the combination of nullOrUndefined and boolean.

The name may be changed to something simpler, like is.render

tychenjiajun avatar Jun 09 '22 08:06 tychenjiajun

What's the practical use-case of this? When would you just want to output any value that React can render and ignore any it cannot? I have done a lot of React work and I cannot say I ever encountered this use-case, some I'm very curious.

sindresorhus avatar Jun 13 '22 18:06 sindresorhus