我有一个以前工作过的项目,使用了react导航的堆栈导航器,但是在大约一天前完成了完美的工作之后,它突然停止了工作。错误是
警告: React.createElement: type无效--预期为字符串(用于内置组件)或类/函数(用于复合组件),但得到:%s.%s%s %s,未定义,您可能忘记从定义在其中的文件导出组件,或者您可能混淆了默认导入和命名导入。
我所有的进口都是正确的,我已经测试过它们,昨天代码也在运行。下面是一个代码示例:
class PreviousQuestions extends React.Component {
firebaseRef
constructor(props){
super(props)
this.state = {
dataArrayDisplay : [],
}
this.firebaseRef = Firebase.database().ref(
`/UserToQuestion/${Firebase.auth().currentUser.uid}`
);
}
async componentDidMount() {
// grab the data from the server and call this.onFirebaseValueChanged every time it changes
this.firebaseRef.orderByValue().on("value", this.onFirebaseValueChanged);
await Font.loadAsync({
Roboto: require('native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
});
this.setState({ isReady: true });
this._notificationSubscription = Notifications.addListener(this._handleNotification)
}
_handleNotification = notification => {
Vibration.vibrate();
console.log(notification);
};
componentWillUnmount() {
// detach all listeners to this reference when component unmounts (very important!)
console.log('unmounting previosu questions')
this.firebaseRef.off();
}
onFirebaseValueChanged = snapshot => {
....
};
renderItem = ({item}) =>{
return(
<Card >
<CardItem >
<Body>
<Text>{item.title}</Text>
</Body>
<Right>
<NativeBaseButton transparent
onPress={() => {this.props.navigation.navigate('Question', {
...})} }>
<Text>View Q</Text>
<Icon active name="arrow-forward" />
</NativeBaseButton>
</Right>
</CardItem>
</Card>
)
}
render(){
if(!this.state.isReady){
return <AppLoading/>
}
else{
return (
<Container>
<Content padder>
<FlatList
style={styles.container}
data={this.state.dataArrayDisplay}
renderItem={this.renderItem}
/>
</Content>
</Container>
);
}
}
}
const styles = StyleSheet.create({
container:{
flex:1
},
})
withNavigation(PreviousQuestions)
function openLink(link){
WebBrowser.openBrowserAsync(link).catch(error => {console.log(error),Alert.alert(error)
})
}
function displayURL(URL){
if(URL != '' && URL != null && URL != undefined){
return(
<CardItem>
<NativeBaseButton transparent textStyle={{color: '#87838B'}}
onPress ={() => openLink(URL)}>
<Text>Click for helpful website</Text>
</NativeBaseButton>
</CardItem>
)
}else{
return(
null
)
}
}
function PreviousQuestionNav({navigation}){
const Stack = createStackNavigator()
console.log('your squestionnav running')
return(
<Stack.Navigator initialRouteName="Your Questions">
<Stack.Screen name="Your Questions" component={PreviousQuestions}
options={{
headerLeft: () => (
<IconButton
icon="menu"
color={Colors.orange500}
size={30}
onPress={() => navigation.openDrawer()}
/>
)
}}/>
<Stack.Screen name="Question" component={Question} />
</Stack.Navigator>
)
}
export default PreviousQuestionNav
function Question({route,navigation}){
return (
<Container>
<Content>
<Card style={{flex: 0}}>
<CardItem>
<Body>
<Text>
sometext
</Text>
<Text>some text</Text>
</Body>
</CardItem>
{displayURL(someURL)}
<CardItem>
</CardItem>
</Card>
</Content>
</Container>
)
}主要问题是:
onPress={() => {this.props.navigation.navigate(‘this.props.navigation.navigate’,{.})} }>
这似乎触发了错误,但到目前为止,它还可以正常工作。是否有一些我不知道地更新过的重大更改,或者我的代码不知何故不正确?谢谢
这是错误

发布于 2020-09-20 20:14:06
我跑了
博览会启动-c
一切都恢复正常了。很明显这是个缓存问题。我从react导航故障排除指南中得到了这一点。https://reactnavigation.org/docs/troubleshooting/#im-getting-an-error-unable-to-resolve-module-after-updating-to-the-latest-version
https://stackoverflow.com/questions/63976970
复制相似问题