React-native-router-flux: How to pass props from navbar to another page?

Created on 5 Jan 2017  路  4Comments  路  Source: aksonov/react-native-router-flux

I have a product view page with rightTitle Edit on navbar. When edit is clicked i want to pass product view state to another page.

How to do this if i use Action.productEdit() in <Scene />

<Scene
 key='product'
 component={Product}
 title='Product'
 rightTitle='Edit'
 onRight={() => { Actions.productEdit({ product: this.props.product }) }} // How can i get the state and pass it to Edit Page?
/>

Most helpful comment

@dragfire I'm dealing with a similar issue, where I want to set the NavBar title based on a value in the Redux store. I tried several things that didn't work. I'm considering creating a new Scene component that is connected to the Redux store like so:

import React from 'react'; 
import { Scene } from 'react-native-router-flux';
import { connect } from 'react-redux';

class SceneWithRedux extends React.Component {
  render() {
    return (
     <Scene title={this.props.productTitle} />
    )
  }
}

function mapStateToProps(state) {
  return {
    productTitle: state.product.title
  }
}
export default connect(mapStateToProps)(SceneWithRedux);

All 4 comments

I think you can't do like that. A quick solution would be:
onRight={ ()=>Actions.refresh({ product: true }) }
Then, in your Product's componentWillReceiveProps

componentWillReceiveProps (props) {
    if (props.product) {
        Actions.productEdit({ product: this.state.product });
    }
}

@vzhen I use Redux to handle this. I dispatch the product id and the Products reducer pulls it from the list and sets is on a sub-state "focus" like so:

products: {
  list: [{鈥],
  focus: {鈥
}

Then, the Product component uses mapStateToProps to map the focus state to its props.

@dragfire I'm dealing with a similar issue, where I want to set the NavBar title based on a value in the Redux store. I tried several things that didn't work. I'm considering creating a new Scene component that is connected to the Redux store like so:

import React from 'react'; 
import { Scene } from 'react-native-router-flux';
import { connect } from 'react-redux';

class SceneWithRedux extends React.Component {
  render() {
    return (
     <Scene title={this.props.productTitle} />
    )
  }
}

function mapStateToProps(state) {
  return {
    productTitle: state.product.title
  }
}
export default connect(mapStateToProps)(SceneWithRedux);

@AndrewHenderson Ohhh, got it. Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rafaelcorreiapoli picture rafaelcorreiapoli  路  3Comments

xnog picture xnog  路  3Comments

basdvries picture basdvries  路  3Comments

sarovin picture sarovin  路  3Comments

GCour picture GCour  路  3Comments