世博会,React-Native]"失败的道具类型"错误

时间:2018-02-12 09:49:54

标签: javascript react-native expo react-proptypes

我正在使用react-native和expo xde制作一个简单易用的应用程序 这是我的回复出错。(develop branch,commit 636543d125d8de2526c4fb7cd35d67d90638d397)
https://github.com/daengdaengLee/to-do-manager/tree/636543d125d8de2526c4fb7cd35d67d90638d397

当我运行我的项目时,它会出错:

Warning: Failed prop type: ActionButton: prop type `eventFunc` is invalid;
it must be a function, usually from the `prop-types` package, but received `undefined`.
    in ActionButton (at App.js:45)
    ...

这是我的App.js出错:

...
render() {
  ...
  return (
    <View style={styles.container}>
      <ActionButton // this is line 45. where the error occurs
        icon="❌"
        eventFunc={() => alert('event func')}
      />
    </View>
  );
}
...

这是我的ActionButton组件:

import React from 'react';
import PropTypes from 'prop-types';

// import Components
import Button from '../../atoms/Button';
import MyView from '../../atoms/MyView';
import MyText from '../../atoms/MyText';

function ActionButton({ icon, eventFunc }) {
  return (
    <Button ownEvent={{ onPressOut: eventFunc }}>
      <MyView styleNames={['iconContainer']}>
        <MyText>
          {icon}
        </MyText>
      </MyView>
    </Button>
  );
}

ActionButton.propTypes = {
  eventFunc: PropTypes.func.isResquired,
  icon: PropTypes.string.isRequired,
};

export default ActionButton;

但是starnge的一个原因是函数() => alert('event func')实际上已经通过了 当我按下按钮时,它会发出警告消息&#39; event func&#39;实际上,
但是错误消息说我没有传递函数并且传递了undefined

是什么让这种奇怪的情况发生? 请帮帮我 谢谢阅读。快乐的编码! :)

1 个答案:

答案 0 :(得分:0)

ActionButton中出现错字:将isResquired更改为isRequired