The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

React Native: Passing data when changing routes

React Native: Passing data when changing routes

2:51
As we build application components, we will need to pass data along as we change routes and bring them into view. With React Native we can do this easily and deliver the appropriate data to our native Dashboard component.
Watch this lesson now
Avatar
egghead.io

As we build application components, we will need to pass data along as we change routes and bring them into view. With React Native we can do this easily and deliver the appropriate data to our native Dashboard component.

Avatar
Eduardo

hey guys,

in the video is missing the moment when we required the "Dashboard.js" in the top "Main.js" file,

// Main.js file
var React = require('react-native');
var api = require('../Utils/api');
var Dashboard = require('./Dashboard');

E

Avatar
Tyler

Good catch! Not sure why that's not shown.

In reply to Eduardo
Avatar
Marty

When Tyler shows the "This is the dashboard" screen in the simulator, I tried to duplicate it and got an error similar to something like:
Invariant Violation string expected but object received. Check the render method of NavigatorIOS.

That's not the exact wording but close. I'm unable to replicate it, but copying Main.js and Dashboard.js from github fixed the issue.

Avatar
Brendan

I'm getting the following error message:
Invariant Violation: Objects are not valid as a React child (found: object with keys{ --keys here-- }. If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of Text.

I've been trying various solutions, and looking for answers but haven't come up with anything yet. Also, I noticed someone had a similar issue a few months ago and copied the Main and Dashboard files from GitHub and it fixed the issue, however I tried that and had no luck.

Any idea on why this is happening?

Avatar
Gunars

I have exactly the same issue. Got the same error message.
Seems it's related with {this.props.userInfo} , because when I'm removing from Dashboard.js, there is no error message.

In reply to Brendan
Avatar
ephemera

I was getting the following error too:
2016-01-04 16:55:42.062 [error][tid:com.facebook.React.RCTExceptionsManagerQueue] Unhandled JS Exception: Invariant Violation: Objects are not valid as a React child (found: object with keys {login, id, avatarurl, gravatarid, url, htmlurl, followersurl, followingurl, gistsurl, starredurl, subscriptionsurl, organizationsurl, reposurl, eventsurl, receivedeventsurl, type, siteadmin, name, company, blog, location, email, hireable, bio, publicrepos, publicgists, followers, following, createdat, updatedat}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of Text.
2016-01-04 16:55:42.093 [warn][tid:main][RCTNavigator.m:507] Cannot adjust current top of stack beyond available views

I believe this is due to Text not being able to render an object as text. Changing
{this.props.userInfo} to {JSON.stringify(this.props.userInfo)} should fix it

In reply to Brendan
Avatar
Tyler

Yup this is a new change to React as of .14 I believe. As you mentioned, JSON.stringify will fix it.

In reply to ephemera
Avatar
Tiago

For those trying to follow this using Navigator instead of NavigatorIOS, I use the following renderScene function:

renderScene={(route, navigator) => {
          return <route.component {...route.passProps} navigator={navigator} />;
        }}

This way your code looks pretty much like the one for NavigatorIOS

Avatar
Dorian

I'm having Possible Unhandled Promise rejection(id: 0) when I try to search for user. Some hints here? I'm using the Navigator rather than NavigatorIOS.

In reply to Tiago
Avatar
Edgar

Had the same problem brotha, glad to see I wasn't the only one! See you at the office :-D

In reply to Brendan
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?