首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >响应导航v5堆栈导航器在使用expo之前工作良好后停止工作

响应导航v5堆栈导航器在使用expo之前工作良好后停止工作
EN

Stack Overflow用户
提问于 2020-09-20 08:24:47
回答 1查看 402关注 0票数 1

我有一个以前工作过的项目,使用了react导航的堆栈导航器,但是在大约一天前完成了完美的工作之后,它突然停止了工作。错误是

警告: React.createElement: type无效--预期为字符串(用于内置组件)或类/函数(用于复合组件),但得到:%s.%s%s %s,未定义,您可能忘记从定义在其中的文件导出组件,或者您可能混淆了默认导入和命名导入。

我所有的进口都是正确的,我已经测试过它们,昨天代码也在运行。下面是一个代码示例:

代码语言:javascript
复制
    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’,{.})} }>

这似乎触发了错误,但到目前为止,它还可以正常工作。是否有一些我不知道地更新过的重大更改,或者我的代码不知何故不正确?谢谢

这是错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63976970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档