React无法识别`tReady`道具

问题描述 投票:1回答:1

我有一个组件,当我想在我的代码中使用它时,出现以下错误: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);

错误消失,但是我的文本组件上没有文本。我该如何解决此错误消息?

javascript reactjs
1个回答
2
投票
© www.soinside.com 2019 - 2024. All rights reserved.