Expo, React-Native] "Failed prop type" 错误
Expo, React-Native] "Failed prop type" error
我正在使用 react-native 和 expo xde 制作一个简单的 To DO 应用程序。
这是我的 repo 出错了。(开发分支,提交 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;
但令人吃惊的是函数 () => alert('event func')
实际上被传递了。
当我按下按钮时,它实际上会发出警告消息 'event func'。
但是错误消息说我没有传递函数并且传递了undefined
。
是什么导致了这种奇怪的情况?
请帮助我。
谢谢阅读。快乐编码! :)
ActionButton
中有错字:将 isResquired
更改为 isRequired
。
我正在使用 react-native 和 expo xde 制作一个简单的 To DO 应用程序。
这是我的 repo 出错了。(开发分支,提交 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;
但令人吃惊的是函数 () => alert('event func')
实际上被传递了。
当我按下按钮时,它实际上会发出警告消息 'event func'。
但是错误消息说我没有传递函数并且传递了undefined
。
是什么导致了这种奇怪的情况?
请帮助我。
谢谢阅读。快乐编码! :)
ActionButton
中有错字:将 isResquired
更改为 isRequired
。