You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
389 B
19 lines
389 B
5 years ago
|
import React from 'react';
|
||
|
|
||
|
export type RenderFunction = () => React.ReactNode;
|
||
|
|
||
|
export const getRenderPropValue = (
|
||
|
propValue?: React.ReactNode | RenderFunction,
|
||
|
): React.ReactNode => {
|
||
|
if (!propValue) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
const isRenderFunction = typeof propValue === 'function';
|
||
|
if (isRenderFunction) {
|
||
|
return (propValue as RenderFunction)();
|
||
|
}
|
||
|
|
||
|
return propValue;
|
||
|
};
|