MCPcopy Index your code
hub / github.com/facebook/react / testStringCoercion

Function testStringCoercion

packages/shared/CheckStringCoercion.js:47–72  ·  view source on GitHub ↗

@noinline

(value: mixed)

Source from the content-addressed store, hash-verified

45
46/** @noinline */
47function testStringCoercion(value: mixed) {
48 // If you ended up here by following an exception call stack, here's what's
49 // happened: you supplied an object or symbol value to React (as a prop, key,
50 // DOM attribute, CSS property, string ref, etc.) and when React tried to
51 // coerce it to a string using `'' + value`, an exception was thrown.
52 //
53 // The most common types that will cause this exception are `Symbol` instances
54 // and Temporal objects like `Temporal.Instant`. But any object that has a
55 // `valueOf` or `[Symbol.toPrimitive]` method that throws will also cause this
56 // exception. (Library authors do this to prevent users from using built-in
57 // numeric operators like `+` or comparison operators like `>=` because custom
58 // methods are needed to perform accurate arithmetic or comparison.)
59 //
60 // To fix the problem, coerce this object or symbol value to a string before
61 // passing it to React. The most reliable way is usually `String(value)`.
62 //
63 // To find which value is throwing, check the browser or debugger console.
64 // Before this exception was thrown, there should be `console.error` output
65 // that shows the type (Symbol, Temporal.PlainDate, etc.) that caused the
66 // problem and how that type was used: key, atrribute, input value prop, etc.
67 // In most cases, this console output also shows the component and its
68 // ancestor components where the exception happened.
69 //
70 // eslint-disable-next-line react-internal/safe-string-coercion
71 return '' + (value: any);
72}
73
74export function checkAttributeStringCoercion(
75 value: mixed,

Callers 8

willCoercionThrowFunction · 0.85
checkKeyStringCoercionFunction · 0.85
checkPropStringCoercionFunction · 0.85
checkHtmlStringCoercionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected