【问题标题】:React props not received in component组件中未收到 React 道具
【发布时间】:2015-11-20 10:47:25
【问题描述】:

我的组件:

class Translate extends React.Component {

  static propTypes = {
    key: React.PropTypes.string.isRequired,
    replacements: React.PropTypes.array
  };

  constructor(props) {
    super(props);

    console.debug('PROPS', props); // Prints empty object

    this.state = props;
  }

..
}

在另一个组件中导入并在 JSX 中使用如下:

import Translate from '/path/to/translate';

...

<Translate key='someKey' />

为什么在 props 中没有收到 key?我有很多其他组件也这样做,我不明白这里出了什么问题。

【问题讨论】:

    标签: javascript reactjs


    【解决方案1】:

    好的,知道了。我根本不能使用“key”作为道具元素(我从这个答案https://stackoverflow.com/a/28826149/1101897 得到的)。使用其他任何东西(例如“消息”)都可以。

    【讨论】:

      猜你喜欢
      • 2015-04-25
      • 1970-01-01
      • 2018-01-10
      • 2018-05-23
      • 2017-12-27
      • 2018-06-03
      • 2023-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多