React Navigation v5 stack navigator 在使用 expo 之前工作正常后停止工作
React Navigation v5 stack navigator stopped working after working fine before with expo
我之前有一个使用 React Navigation 的堆栈导航器的工作项目,但在大约一天前完美运行后突然停止工作。
错误是
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s%s, undefined, You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
我所有的导入都是正确的,我已经测试了它们并且代码昨天运行正常。这是一个代码示例:
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('Question', {
...})} }>
这似乎触发了错误,但直到现在它都运行良好。
是否有一些我在不知不觉中更新的重大更改,或者我的代码不知何故不正确?谢谢
这里是错误
我运行
expo start -c
一切又开始正常工作了。显然这是一个缓存问题。
我从反应导航故障排除指南中得到了它。
https://reactnavigation.org/docs/troubleshooting/#im-getting-an-error-unable-to-resolve-module-after-updating-to-the-latest-version
我之前有一个使用 React Navigation 的堆栈导航器的工作项目,但在大约一天前完美运行后突然停止工作。 错误是
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s%s, undefined, You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
我所有的导入都是正确的,我已经测试了它们并且代码昨天运行正常。这是一个代码示例:
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('Question', { ...})} }>
这似乎触发了错误,但直到现在它都运行良好。 是否有一些我在不知不觉中更新的重大更改,或者我的代码不知何故不正确?谢谢
这里是错误
我运行
expo start -c
一切又开始正常工作了。显然这是一个缓存问题。 我从反应导航故障排除指南中得到了它。 https://reactnavigation.org/docs/troubleshooting/#im-getting-an-error-unable-to-resolve-module-after-updating-to-the-latest-version