Cannot add a child node that doesn't have a YogaNode to a parent without measure function

淺唱寂寞╮ 提交于 2021-02-19 05:18:41

问题


Click here for an image of the screenshot

Trying to create a log-in form which reads information from a firebase database through axios; getting an error related to YogaNodes. Read about this; I think there must be something wrong with the JSX syntax. But both SublimeLinter (the text editor I use) and I can't seem to figure out what's wrong.

Pretty sure the components imported (Card, CardSection, Button, Spinner) are fine since those are reusable components I have been using with my other Apps.

import React, { Component } from 'react';
import { View } from 'react-native';
import axios from 'axios';
import firebase from 'firebase';
import { Header, Button, Spinner, CardSection, AlbumDetail } from './components/common';
import LoginForm from './components/LoginForm';

class App extends Component {
    state = { loggedIn: null, albums: [] };

 componentWillMount() {
 firebase.initializeApp({
 apiKey: 'xx',
 authDomain: 'xx',
 databaseURL: 'xx',
 projectId: 'xx',
 storageBucket: 'xx',
 messagingSenderId: 'xx'
});

    axios.get('https://xx')
            .then(response => this.setState({ albums: response.data }));

    firebase.auth().onAuthStateChanged((user) => {
      if (user) {
        this.setState({ loggedIn: true });
      } else {
        this.setState({ loggedIn: false });
      }
    });
  }

  renderAlbums() {
        return this.state.albums.map(album => 
            <AlbumDetail key={album.District} album={album} />);
    }

  renderContent() {
    switch (this.state.loggedIn) {
      case true:
        return (
        <CardSection>
          <Button onPress={() => firebase.auth().signOut()}>
            Log Out
          </Button>
        </CardSection>  
        );
      case false:
        return <LoginForm />;
      default:
        return <Spinner size='large' />;
    }
  }

  render() {
    return (
      <View>
        <Header headerText='Authentication' />
        console.log(this.state.albums)
        {this.renderContent()}
      </View>
    );
  }
}

export default App;

Any help would be appreciated.


回答1:


I believe you need to add a <Text> tag around Text inside of <Button>, or you can throw the text in the title attribute.

        <CardSection>
          <Button onPress={() => firebase.auth().signOut()}>
            <Text>Log Out</Text>
          </Button>
        </CardSection>



回答2:


Copied from GitHub (https://github.com/facebook/react-native/issues/13243#issuecomment-335488473):

I got this error in RN 0.49.1 in some conditional JSX that relied on a value's being truthy to decide whether a View shows up or not. I fixed the error using the classic double exclamation !!, i.e. "{!!value" instead of "{value."

It helps me



来源:https://stackoverflow.com/questions/48359839/cannot-add-a-child-node-that-doesnt-have-a-yoganode-to-a-parent-without-measure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!