Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add a child that doesn't have a YogaNode to a parent without a measure function! (Trying to add a 'ReactRawTextShadowNode' to a 'LayoutShadow

According on this tutorial, this is my component which I use for a react base component as a side bar component, and its working very well, but the problem starts when I change list items from <Text> to <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>
        );
    }
}

I get this error:

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

cant understand this error at all and didn't saw any thing about it on net!

> 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
like image 699
Iman Salehi Avatar asked Dec 04 '17 05:12

Iman Salehi


1 Answers

For others landing on this page due to the same error message as the OP, there are a whole host of issues that can cause same error message.
There is an GitHub issue surrounding this generic error message.

Probably the most common reasons are:

  • text to be rendered is not wrapped in <Text> tags
  • syntax error in JSX (for example, a ;, or a malformed tag)
  • a space between JSX comments and a JSX tag, if you use Prettier
    (it seems Prettier puts an automatic ; insertion,
    (solution: move the JSX comment to its own line)

  • some value is assumed to be null, but it's undefined, or an ''(empty string).
    In the case of an '', it would need to be wrapped in <Text> (see 1st item above)

  • not wrapping child tags (ScrollView in particular)
  • space between two adjacent tags
  • an issue with 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.

I highly recommend taking a gander if you are having trouble finding the source of your error: https://github.com/facebook/react-native/issues/13243

As one person 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..

like image 74
SherylHohman Avatar answered Oct 22 '22 14:10

SherylHohman