我有一个组件,当我想在我的代码中使用它时,出现以下错误:React无法识别tReady
道具“我的组件是
import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
const Text = ({ t, text, ...rest }) => (
<div {...rest}>{t(text)}</div>
);
Text.propTypes = {
text: PropTypes.string.isRequired,
t: PropTypes.func.isRequired
};
export default withTranslation()(Text);
我在另一个文件中使用它,但出现此错误。我尝试更改组件,例如:
import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
const Text= ({ children, ...rest }) => (
<div>
{children}
</div>
);
Text.propTypes = {
text: PropTypes.string.isRequired,
t: PropTypes.func.isRequired
};
export default withTranslation()(Text);
错误消失,但是我的文本组件上没有文本。我该如何解决此错误消息?