mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Change name from SafeReactNode to StrictReactNode
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
e88de58b5d
commit
d8823085a8
75 files changed
+219
-210
No files matched your search
@@ -5,15 +5,25 @@
|
||||
|
||||
import React from "react";
|
||||
import { isObject } from "./type-narrowing";
|
||||
import type { SingleOrMany } from "./types";
|
||||
|
||||
export type SafeReactNode = React.ReactElement | React.ReactText | boolean | null | undefined | Iterable<SafeReactNode>;
|
||||
export type StrictReactFragment =
|
||||
| {
|
||||
key?: string | number | null;
|
||||
ref?: null;
|
||||
props?: {
|
||||
children?: StrictReactNode;
|
||||
};
|
||||
};
|
||||
|
||||
export function toSafeReactChildrenArray(children: SafeReactNode) {
|
||||
return React.Children.toArray(children) as (Exclude<SafeReactNode, boolean | null | undefined>)[];
|
||||
}
|
||||
export type StrictReactNode =
|
||||
| React.ReactChild
|
||||
| StrictReactFragment
|
||||
| React.ReactPortal
|
||||
| boolean
|
||||
| null
|
||||
| undefined;
|
||||
|
||||
export function isReactNode(node: unknown): node is SafeReactNode {
|
||||
export function isReactNode(node: unknown): node is StrictReactNode {
|
||||
return (isObject(node) && React.isValidElement(node))
|
||||
|| Array.isArray(node) && node.every(isReactNode)
|
||||
|| node == null
|
||||
|
||||
Reference in new issue
Block a user