source: node_modules/react-redux/src/utils/react-is.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 3.5 KB
Line 
1import type { ElementType, MemoExoticComponent, ReactElement } from 'react'
2import { React } from './react'
3
4// Directly ported from:
5// https://unpkg.com/browse/react-is@19.0.0/cjs/react-is.production.js
6// It's very possible this could change in the future, but given that
7// we only use these in `connect`, this is a low priority.
8
9export const IS_REACT_19 = /* @__PURE__ */ React.version.startsWith('19')
10
11const REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for(
12 IS_REACT_19 ? 'react.transitional.element' : 'react.element',
13)
14const REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for('react.portal')
15const REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for('react.fragment')
16const REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for('react.strict_mode')
17const REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for('react.profiler')
18const REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for('react.consumer')
19const REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for('react.context')
20const REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for('react.forward_ref')
21const REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for('react.suspense')
22const REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol.for(
23 'react.suspense_list',
24)
25const REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for('react.memo')
26const REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for('react.lazy')
27const REACT_OFFSCREEN_TYPE = /* @__PURE__ */ Symbol.for('react.offscreen')
28const REACT_CLIENT_REFERENCE = /* @__PURE__ */ Symbol.for(
29 'react.client.reference',
30)
31
32export const ForwardRef = REACT_FORWARD_REF_TYPE
33export const Memo = REACT_MEMO_TYPE
34
35export function isValidElementType(type: any): type is ElementType {
36 return typeof type === 'string' ||
37 typeof type === 'function' ||
38 type === REACT_FRAGMENT_TYPE ||
39 type === REACT_PROFILER_TYPE ||
40 type === REACT_STRICT_MODE_TYPE ||
41 type === REACT_SUSPENSE_TYPE ||
42 type === REACT_SUSPENSE_LIST_TYPE ||
43 type === REACT_OFFSCREEN_TYPE ||
44 (typeof type === 'object' &&
45 type !== null &&
46 (type.$$typeof === REACT_LAZY_TYPE ||
47 type.$$typeof === REACT_MEMO_TYPE ||
48 type.$$typeof === REACT_CONTEXT_TYPE ||
49 type.$$typeof === REACT_CONSUMER_TYPE ||
50 type.$$typeof === REACT_FORWARD_REF_TYPE ||
51 type.$$typeof === REACT_CLIENT_REFERENCE ||
52 type.getModuleId !== undefined))
53 ? !0
54 : !1
55}
56
57function typeOf(object: any): symbol | undefined {
58 if (typeof object === 'object' && object !== null) {
59 const { $$typeof } = object
60
61 switch ($$typeof) {
62 case REACT_ELEMENT_TYPE:
63 switch (((object = object.type), object)) {
64 case REACT_FRAGMENT_TYPE:
65 case REACT_PROFILER_TYPE:
66 case REACT_STRICT_MODE_TYPE:
67 case REACT_SUSPENSE_TYPE:
68 case REACT_SUSPENSE_LIST_TYPE:
69 return object
70 default:
71 switch (((object = object && object.$$typeof), object)) {
72 case REACT_CONTEXT_TYPE:
73 case REACT_FORWARD_REF_TYPE:
74 case REACT_LAZY_TYPE:
75 case REACT_MEMO_TYPE:
76 return object
77 case REACT_CONSUMER_TYPE:
78 return object
79 default:
80 return $$typeof
81 }
82 }
83 case REACT_PORTAL_TYPE:
84 return $$typeof
85 }
86 }
87}
88
89export function isContextConsumer(object: any): object is ReactElement {
90 return IS_REACT_19
91 ? typeOf(object) === REACT_CONSUMER_TYPE
92 : typeOf(object) === REACT_CONTEXT_TYPE
93}
94
95export function isMemo(object: any): object is MemoExoticComponent<any> {
96 return typeOf(object) === REACT_MEMO_TYPE
97}
Note: See TracBrowser for help on using the repository browser.