[英]Expo, React-Native] "Failed prop type" error
I'm making a simple To DO App with react-native and expo xde.我正在使用 react-native 和 expo xde 制作一个简单的 To DO 应用程序。
This is my repo that makes error.(develop branch, commit 636543d125d8de2526c4fb7cd35d67d90638d397)这是我的 repo 出错了。(开发分支,提交 636543d125d8de2526c4fb7cd35d67d90638d397)
https://github.com/daengdaengLee/to-do-manager/tree/636543d125d8de2526c4fb7cd35d67d90638d397 https://github.com/daengdaengLee/to-do-manager/tree/636543d125d8de2526c4fb7cd35d67d90638d397
When I run my project, it makes the error:当我运行我的项目时,它会出错:
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)
...
This is my App.js where makes the error:这是我的 App.js 出错的地方:
...
render() {
...
return (
<View style={styles.container}>
<ActionButton // this is line 45. where the error occurs
icon="❌"
eventFunc={() => alert('event func')}
/>
</View>
);
}
...
This is my ActionButton Component:这是我的 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;
But something starnge is that the function () => alert('event func')
is actually passed.但最重要的是函数
() => alert('event func')
实际被传递了。
When I press out the Button, it makes the alert message 'event func' actually.当我按下按钮时,它实际上使警报消息“事件功能”。
But the error message said that I'm not passing the function and undefined
is passed.但是错误消息说我没有传递函数,而是传递了
undefined
。
What makes this weird situation?是什么造成了这种奇怪的情况?
Please Help me.请帮我。
Thanks for reading.谢谢阅读。 Happy Coding!
快乐编码! :)
:)
有一个错字ActionButton
:改变isResquired
到isRequired
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.