MCPcopy
hub / github.com/facebook/react / describeValueForErrorMessage

Function describeValueForErrorMessage

packages/shared/ReactSerializationErrors.js:104–135  ·  view source on GitHub ↗
(value: mixed)

Source from the content-addressed store, hash-verified

102}
103
104export function describeValueForErrorMessage(value: mixed): string {
105 switch (typeof value) {
106 case 'string': {
107 return JSON.stringify(
108 value.length <= 10 ? value : value.slice(0, 10) + '...',
109 );
110 }
111 case 'object': {
112 if (isArray(value)) {
113 return '[...]';
114 }
115 if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
116 return describeClientReference(value);
117 }
118 const name = objectName(value);
119 if (name === 'Object') {
120 return '{...}';
121 }
122 return name;
123 }
124 case 'function': {
125 if ((value: any).$$typeof === CLIENT_REFERENCE_TAG) {
126 return describeClientReference(value);
127 }
128 const name = (value: any).displayName || value.name;
129 return name ? 'function ' + name : 'function';
130 }
131 default:
132 // eslint-disable-next-line react-internal/safe-string-coercion
133 return String(value);
134 }
135}
136
137function describeElementType(type: any): string {
138 if (typeof type === 'string') {

Callers 1

Calls 3

isArrayFunction · 0.85
describeClientReferenceFunction · 0.85
objectNameFunction · 0.70

Tested by

no test coverage detected