我正在使用解析器功能。此函数返回一个对象,其值是一条错误消息:这是代码:
const codeErrors = ({ code }) => {
if (code === '1111') {
return {
'contact1': (
<ErrorWrapper id={code} />
)
};
}
return {
'contact2': (
<ErrorWrapper id={code} />
)
};
ErrorWraper组件只是具有以下代码的React组件:
const ErrorWrapperComponent = ({ id, locale, serverErrorMessages, values, defaultMessage }) => (
id ? (
<React.Fragment>
{console.log(id)}
<FormattedMessage
id={id}
values={values}
defaultMessage={defaultMessage || `${CLIENT_ERROR_MESSAGES[locale].generalError} (${id})`}
/>
{serverErrorMessages && serverErrorMessages[id] && ` (${id})`}
</React.Fragment>
) : null
);
但是,在渲染错误时,出现了无数次无法在Symbol(react.element)中使用“in”运算符搜索“toMap”的错误。为什么会这样呢?
最佳答案
从Mozilla:
The in operator can only be used to check if a property is in an object. You can't search in strings, or in numbers, or other primitive types.
"Hello" in "Hello World";
// TypeError: cannot use 'in' operator to search for 'Hello' in 'Hello World'
相反,您将需要使用例如String.prototype.indexOf()。
"Hello World".indexOf("Hello") !== -1;
// true
关于javascript - 无法使用 'in'运算符在Symbol(react.element)错误中搜索 'toMap',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59139485/