forked from shakacode/react_on_rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisRenderFunction.ts
30 lines (26 loc) · 953 Bytes
/
isRenderFunction.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// See discussion:
// https://discuss.reactjs.org/t/how-to-determine-if-js-object-is-react-component/2825/2
import { ReactComponentOrRenderFunction, RenderFunction } from "./types/index";
/**
* Used to determine we'll call be calling React.createElement on the component of if this is a
* Render-Function used return a function that takes props to return a React element
* @param component
* @returns {boolean}
*/
export default function isRenderFunction(component: ReactComponentOrRenderFunction): boolean {
// No for es5 or es6 React Component
if (
(component as RenderFunction).prototype &&
(component as RenderFunction).prototype.isReactComponent) {
return false;
}
if ((component as RenderFunction).renderFunction) {
return true;
}
// If zero or one args, then we know that this is a regular function that will
// return a React component
if (component.length >= 2) {
return true;
}
return false;
}