Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigator Invariant Violation: onlyChild must be passed children with exactly one child

Tags:

react-native

I have an error when i use Navigator and TouchableHighlight in my app this is the code for my index.ios.js (render and renderScene functions):

      render: function() {

        return (
          <View>
          <Navigator
           renderScene={this.renderScene}>
          </Navigator>
          </View>
       )
      },

     renderScene: function(route, nav) {
          return <LoginView navigator={nav} />;
     }

and this is the code for the LoginView

    var LoginView = React.createClass({
      onPress: function() {

      },
      render: function() {

        return (

            <View>
              <TouchableHighlight />
            </View>

        )
      },
    });

I'm sure this happens because of the fact that TouchableHighlight can only have one child (in the render function of TouchableHihglight.js there is a use of the onlyChild function from onlyChild.js to verify the number of children) What I do not understand is why in my case TouchableHighlight has more than one child (as I see it there are no children at all)???

hope you help me guys (:

like image 564
Dima Golovin Avatar asked Dec 07 '15 23:12

Dima Golovin


1 Answers

You need to pass in one child to TouchableHighlight. Something like this:

<TouchableHighlight>
  <Text>Hello</Text>
</TouchableHighlight>

Will eliminate the error.

like image 181
Nader Dabit Avatar answered Oct 22 '22 17:10

Nader Dabit