Javascript “世博会,反应本土]”;失败的支柱类型“;错误
我正在用react native和expo xde制作一个简单易用的应用程序。Javascript “世博会,反应本土]”;失败的支柱类型“;错误,javascript,react-native,expo,react-proptypes,Javascript,React Native,Expo,React Proptypes,我正在用react native和expo xde制作一个简单易用的应用程序。 这是我犯错误的回购协议。(开发分支,提交636543d125d8de2526c4fb7cd35d67d90638d397) 运行项目时,会出现以下错误: Warning: Failed prop type: ActionButton: prop type `eventFunc` is invalid; it must be a function, usually from the `prop-types` pack
这是我犯错误的回购协议。(开发分支,提交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)
...
...
render() {
...
return (
<View style={styles.container}>
<ActionButton // this is line 45. where the error occurs
icon="❌"
eventFunc={() => alert('event func')}
/>
</View>
);
}
...
这是我的App.js,其中出错:
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)
...
...
render() {
...
return (
<View style={styles.container}>
<ActionButton // this is line 45. where the error occurs
icon="❌"
eventFunc={() => alert('event func')}
/>
</View>
);
}
...
。。。
render(){
...
返回(
警报('event func')}
/>
);
}
...
这是我的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;
从“React”导入React;
从“道具类型”导入道具类型;
//导入组件
从“../../atoms/Button”导入按钮;
从“../../atoms/MyView”导入MyView;
从“../../atoms/MyText”导入MyText;
函数ActionButton({icon,eventFunc}){
返回(
{icon}
);
}
ActionButton.propTypes={
eventFunc:PropTypes.func.isrequired,
图标:PropTypes.string.isRequired,
};
导出默认操作按钮;
但最重要的是函数()=>alert('event func')
实际上已传递。当我按下按钮时,它实际上会发出警报消息“event func”。
但是错误消息说我没有传递函数,并且传递了
undefined
是什么造成了这种奇怪的局面?请帮帮我。
谢谢你的阅读。快乐编码!:) 操作按钮中有一个输入错误:
isRequired
改为isRequired
而不是GitHub您能在问题中直接编写一些代码吗?应该是演示问题所需的最小代码量。哦,天哪,我明白了!非常感谢。我很愚蠢。。。有一个很好的编码!