question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

passProps seem doesn't work

See original GitHub issue

I call this.props.navigator.push to the next scene, and pass some props to the next scene, and caught an error, the passed prop is undefined in the next view,it seems passProps doesn’t work,and code is below:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';

var React = require('react-native');
var Product = require('./product');
var Adapt = require('./adapt');

var mdskip = require('./data/mock-mdskip');
var context = require('./data/mock-context');
var NavigationBar = require('react-native-navbar');

var Detail = require("./ui/detail");
var styles = require("./ui/style");
var {
  Navigator,
  NavigatorIOS,
  AppRegistry,
  View,
  Text,
  StyleSheet,
  TouchableHighlight,
  ScrollView
} = React;

var product = new Product();
product.set("context", context.ModuleDatas);
product.set("config", context.TDetail);
product.set("mdskip", Adapt.transform(mdskip));
product.set("deviceType", "phone");

var RootComponent = React.createClass({
  getInitialState: function(){
    return {};
  },
  componentDidMount: function() {
    var self = this;
  },
  renderScene: function(route, navigator) {
    var product = this.state.product;

    var Component = route.component;
    var navBar = route.navigationBar;

    if (navBar) {
      navBar = React.addons.cloneWithProps(navBar, {
        navigator: navigator,
        route: route
      });
    }

    return (
      <View style={styles.navigator}>
        {navBar}
        <Component navigator={navigator} route={route} product={product} />
      </View>
    );
  },
  render: function() {

    if(context){
      return (
        <Navigator
        style={styles.navigator}
        renderScene={this.renderScene}
        initialRoute={{
          component: Entrance,
          navigationBar: <NavigationBar
            title="Initial View"
            onNext={this.handleNext}
          />
        }}
      />
      );
    }else{
      return (
        <View></View>
      )
    }
  }
});

var Entrance = React.createClass({
  render: function(){
    return (
      <View style={styles.clickMe}>
        <TouchableHighlight onPress={this.onPress} underlayColor="#B5B5B5">
          <Text style={styles.clickMeText}>点我看详情</Text>
        </TouchableHighlight>
      </View>
    );
  },
  componentDidMount(){
    var self = this;
    product.onLoad(["context", "config", "mdskip"], function(context, config, mdskip){
      self.setState({
        "context": context,
        "config": config,
        "mdskip": mdskip
      });
    })
  },
  onPress: function(){
    var context = this.state.context;
    var config = this.state.config;
    var mdskip = this.state.mdskip;
    var product = this.props.product;

    this.props.navigator.push({
      title: context.title.itemTitle,
      component: DetailMain,
      backButtonTitle: 'Back',
      passProps: { config: config, mdskip: mdskip, product: product, context: context}
    });
  }
});

var DetailMain = React.createClass({
  getInitialState: function(){
    return {
      loading: false
    };
  },
  render: function(){
    return (
      <Detail config={this.props.config} mdskip={this.props.mdskip} product={this.props.product} context={this.props.context} navigator={this.props.navigator}/>
    )
  }
})

AppRegistry.registerComponent('DetailNative', () => RootComponent);

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:26 (10 by maintainers)

github_iconTop GitHub Comments

13reactions
Kureevcommented, Nov 18, 2015

那么,它(导航栏)改变了很多,因为在这里的最后一个注释。你使用哪种版本?你能为我们提供一个代码示例?@Yidada

P.S. Google translate FTW!

7reactions
toearthcommented, Jun 23, 2016

I solve this problem by rendering scenes this way <Component {...route.passProps} navigator={navigator} route={route} />

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing props to ReferenceArrayField doesn't seem to work
When passing the pagination, perPage and sort props to reference array component they don't seem to be applied. I have a similar view...
Read more >
How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >
passing children via props does not work properly on React ...
The way to pass children in a .astro file is via the content, not props. Once you're in a React component you pass...
Read more >
How to use Props in React - Robin Wieruch
Passing props from component to component in React doesn't make components interactive, because props are read-only and therefore immutable.
Read more >
Higher-Order Components - React
While the convention for higher-order components is to pass through all props to the wrapped component, this does not work for refs. That's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found