【问题标题】:React native : Component nothing was returned from the render (UiKitten)React native:组件没有从渲染中返回(UiKitten)
【发布时间】:2020-12-18 08:42:28
【问题描述】:

我有这个问题,我的代码运行良好,但如果我输入Accessory Right or Left,我会收到错误Nothing was returned from the render。在其他屏幕上它工作得很好,但在这个屏幕上它是不可能的。 UIKItten 有些东西我真的不明白。感谢您的帮助。

  userChange = () =>  {
    this.state.navigation.navigate('Login', {noAutoConnect : true});
  }

  Disconnect = () => {
    <TopNavigationAction icon={Quit} onPress={this.userChange}/>
  }
  
  render() {    
    return (
        <>
          <TopNavigation style={{ borderWidth: 1 }} title='Acceuil' alignment='center' accessoryLeft = {this.Disconnect}  />
            <View style = {style.lay}>
              <Button size = "giant" onPress = {this.navigateArticles} status = "danger"><Text>Accéder à mes Pdf</Text></Button>
            </View>
       </>
    );
  }

【问题讨论】:

    标签: react-native react-native-ui-kitten


    【解决方案1】:

    Disconnect函数中添加return

    Disconnect = () => {
        return <TopNavigationAction icon={Quit} onPress={this.userChange}/>
    }
    

    【讨论】:

    • 它有效,谢谢。但我不明白为什么我需要在这个屏幕上返回而不是在另一个屏幕上返回相同的功能
    • @Dirk 因为在这种情况下accessoryLeft 需要一些 UI 元素,这就是为什么你需要从 Disconnect 函数返回一些东西的原因。传递唯一的引用是不够的。
    • 如果你想更新状态或做任何其他事情,那么没有必要返回一些东西。
    • 好吧,我猜navigation.goBack()navigation.navigate() 不被认为是相似的。这就是为什么它在我的其他屏幕上运行良好的原因。非常感谢!
    猜你喜欢
    • 2018-07-09
    • 2021-11-18
    • 2016-12-15
    • 2020-09-14
    • 2018-12-20
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多