chore: Change name from SafeReactNode to StrictReactNode

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2023-05-15 11:56:30 -04:00
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