GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lowcode-engine/packages/utils/src/is-react.ts at main · jackokcc/lowcode-engine

Expand file tree

/

is-react.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
51 lines (42 loc) · 1.75 KB
/

is-react.ts

Copy path

File metadata and controls

51 lines (42 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { ComponentClass, Component, FunctionComponent, ComponentType, createElement } from 'react';
import { cloneEnumerableProperty } from './clone-enumerable-property';
const hasSymbol = typeof Symbol === 'function' && Symbol.for;
const REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
export function isReactClass(obj: any): obj is ComponentClass<any> {
return obj && obj.prototype && (obj.prototype.isReactComponent || obj.prototype instanceof Component);
}
export function acceptsRef(obj: any): boolean {
return obj?.prototype?.isReactComponent || isForwardOrMemoForward(obj);
}
export function isForwardRefType(obj: any): boolean {
return obj?.$$typeof && obj?.$$typeof === REACT_FORWARD_REF_TYPE;
}
function isMemoType(obj: any): boolean {
return obj?.$$typeof && obj.$$typeof === REACT_MEMO_TYPE;
}
export function isForwardOrMemoForward(obj: any): boolean {
return obj?.$$typeof && (
// React.forwardRef(..)
isForwardRefType(obj) ||
// React.memo(React.forwardRef(..))
(isMemoType(obj) && isForwardRefType(obj.type))
);
}
export function isReactComponent(obj: any): obj is ComponentType<any> {
if (!obj) {
return false;
}
return Boolean(isReactClass(obj) || typeof obj === 'function' || isForwardRefType(obj) || isMemoType(obj));
}
export function wrapReactClass(view: FunctionComponent) {
let ViewComponentClass = class extends Component {
render() {
const { children, ...other } = this.props;
return createElement(view, other, children);
}
} as any;
ViewComponentClass = cloneEnumerableProperty(ViewComponentClass, view);
ViewComponentClass.displayName = view.displayName;
return ViewComponentClass;
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.