javascript - 无法将没有 YogaNode 的 child 添加到没有测量功能的 parent ! (试图将 'ReactRawTextShadowNode' 添加到 'LayoutShadow

标签 javascript react-native native-base

根据this教程,这是我用于 react base 组件作为侧边栏组件的组件,它工作得很好,但是当我从 <Text> 更改列表项时问题就开始了至 <Button>

    import { Text, Container, Header, Content, List, ListItem, TextBody, Button } from 'native-base';
import { StackNavigator, DrawerNavigator } from 'react-navigation'

export default class SideBar extends Component {

    render() {
        return (
            <Content style={{ backgroundColor: '#ffffff' }}>
                <Container>

                    <Content>
                        <List>
                            <ListItem>
                                <Text>First</Text>
                            </ListItem>
                            <ListItem>
                                <Text>Secount</Text>
                            </ListItem>
                            <ListItem>
                                <Text>Third</Text>
                            </ListItem>
                        </List>
                    </Content>
                </Container>
            </Content>
        );
    }
}

我收到这个错误:

cant add a child that doesn't have a YogaNede to parent without the measure function !(Trying to Add a 'ReactRawTextshadow' to a 'LayoutShadowNode' )

根本无法理解这个错误,也没有在网上看到任何关于它的信息!

> Cannot add a child that doesn't have a YogaNode to a parent without a
> measure function! (Trying to add a 'ReactRawTextShadowNode' to a
> 'LayoutShadowNode') addChildAt
>     ReactShadowNodeImpl.java:199 addChildAt
>     ReactShadowNodeImpl.java:54 setChildren
>     UIImplementation.java:472 setChildren
>     UIManagerModule.java:436 invoke
>     Method.java invoke
>     Method.java:372 invoke
>     JavaMethodWrapper.java:374 invoke
>     JavaModuleWrapper.java:162 run
>     NativeRunnable.java handleCallback
>     Handler.java:739 dispatchMessage
>     Handler.java:95 dispatchMessage
>     MessageQueueThreadHandler.java:31 loop
>     Looper.java:135 run
>     MessageQueueThreadImpl.java:194 run
>     Thread.java:818

最佳答案

对于由于与 OP 相同的错误消息而登陆此页面的其他人, 有很多问题会导致相同的错误消息。
有一个 GitHub issue围绕此一般错误消息。

可能最常见的原因是:

  • 要呈现的文本未包含在 <Text> 标签
  • JSX 中的语法错误(例如 ; 或格式错误的标记)
  • 如果您使用 Prettier,则在 JSX 注释和 JSX 标记之间留一个空格
    (看起来 Prettier 自动插入了一个 ;
    (解决方案:将 JSX 注释移到它自己的行)

  • 一些值假定为 null , 但它是 undefined ,或 '' (空字符串)。
    '' 的情况下, 它需要包裹在 <Text> 中(看 上面第一项)

  • 不包装子标签 ( ScrollView in particular )
  • space between two adjacent tags
  • CSS 的问题

    If a CSS node has measure defined, the layout algorithm will not visit its children. Even more, it asserts that you don't add children to nodes with measure functions.

如果您无法找到错误的根源,我强烈建议您看一看: <强> https://github.com/facebook/react-native/issues/13243

作为一个人wrote :

To summarize:
This issue is about what React Native perceives to be mal formatted JSX (usually occurring on Android render) and this thread has done a good job documenting the many forms this malformatted JSX can come in.

It Still doesn't solve the need for developers to comb through their code line by line looking for a random semicolons or spaces.

If there is a way to have the stack trace be more specific about the specific offending character or error, that would probably save devs hours of sad debugging..

关于javascript - 无法将没有 YogaNode 的 child 添加到没有测量功能的 parent ! (试图将 'ReactRawTextShadowNode' 添加到 'LayoutShadow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47627231/

相关文章:

reactjs - 为什么 TypeScript 告诉我 NativeBase 的 Button Component 上不存在某个属性,但仍然呈现它?

javascript - 使用 Google Maps API 从当前缩放级别获取最大查看距离

reactjs - React原生组件生命周期: `ref` usage and `null` object

ios - 如何从我的应用程序打开其他应用程序

javascript - 0.59.9版本的React Native项目创建时报错: couldn't find template. config.js

javascript - react native onChange 事件的名称类型值未定义

javascript - useState 与异步函数返回 Promise {<pending>}

javascript - Ionic、angularjs、bootstrap 3 的左侧多级菜单无法正常工作

javascript - javascript中 ionic 改变进度条条颜色