mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-24 17:44:50 +03:00
25 lines
665 B
JavaScript
25 lines
665 B
JavaScript
import * as React from "react";
|
|
|
|
export const Match = React.memo(({ children /** when */ }) => {
|
|
return children;
|
|
});
|
|
// NOTE(amine): displayName is used to assert that direct children of Switch are the Match components
|
|
Match.displayName = "$";
|
|
|
|
export const Switch = React.memo(({ children, fallback = null }) => {
|
|
if (Array.isArray(children)) {
|
|
for (let element of children) {
|
|
if (element.type.displayName !== "$")
|
|
console.error("Switch component requires Match component as its children");
|
|
|
|
if (element.props.when) return element;
|
|
}
|
|
|
|
return fallback;
|
|
}
|
|
|
|
if (children?.props?.when) return children;
|
|
|
|
return fallback;
|
|
});
|