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