I have the following piece of code (codesandbox):
import { ComponentType, ReactNode } from "react";
type DatetimeCell = ({ value }: { value: string }) => ReactNode;
function getDateTimeCell(): DatetimeCell {
return ({ value }) => value;
}
function buildCell({
value
}: {
value: string;
}): ComponentType<{ value: string }> {
const DateTimeCell = getDateTimeCell();
return ({ value }) => <DateTimeCell value={value} />;
}
When returning in buildCell
I get the error:
'DateTimeCell' cannot be used as a JSX component.
Its return type 'ReactNode' is not a valid JSX element.
I thought ReactNode
would be the most general type for valid JSX, but it seems like that is not the case.
Why is ReactNode
not valid JSX and how can I solve this issue?
Edit:
I know that wrapping value
in React fragments solves the issue. However, in this specific application I need the type DatetimeCell
to be able to return any valid JSX. So string
should be included.