Coder Social home page Coder Social logo

Comments (5)

kcfgl avatar kcfgl commented on July 22, 2024

+1 on this.

I've been attempting to build some custom routes to be able to do something like:

if (action.type === PUSH_NEW_ROUTE_WITH_PROPS) {
       console.log('push new route with props');
        globalNav.navigator.push({id: action.route, passProps: {bookID: '12341'}});
        return {
            routes: [...state.routes, action.route]
        };
    }

Where ultimately I could pass in the bookID dynamically to the Action. And then on the new view access the prop with:
this.props.bookID

But when I log the prop in the console it returns undefined.

from native-starter-kit.

Proxiweb avatar Proxiweb commented on July 22, 2024

It work for me like this :

  • In the bindAction add passProps
function bindAction(dispatch) {
  return {
     closeDrawer: () => dispatch(closeDrawer()),
     replaceOrPushRoute:(route, passProps) => dispatch(replaceOrPushRoute(route, passProps))
  }
}
  • In the container adapt the method
 navigateTo(route, passProps) {
      this.props.closeDrawer();
      this.props.replaceOrPushRoute(route, passProps);
 }
  • In the scene rendered for this route you can access passProps
const routes = this.props.navigator.getCurrentRoutes();
console.log(routes[routes.length -1].passProps)

from native-starter-kit.

johntom avatar johntom commented on July 22, 2024

Hi,
I tried your example but have something wrong. Code below. I created a public gist to view all code https://gist.github.com/johntom/7c2ee9b6bb22abe2e14aee852c9469dd.
Thanks
John
login/index.js
replaceRoute(route, passProps) {

    console.log(' pssProps',passProps)
    passProps.userid ='11766' // this emulates fetch of user getting the userid and adding to passProps
    console.log('s ',passProps)
   // route = home
    this.props.replaceRoute(route, passProps)
}

function bindActions(dispatch) {
return {
closeDrawer: () => dispatch(closeDrawer()),
replaceRoute: (route, passProps) => dispatch(replaceRoute(route, passProps)),
pushNewRoute: (route) => dispatch(pushNewRoute(route))
}
}
home/index.js
constructor(props) {
super(props);
console.log('home props ',props)

    const routes = props.navigator.getCurrentRoutes();

    let pp = routes[routes.length -1].passProps;
    console.log('pp ',pp) // nothing here
}

from native-starter-kit.

krishbhattacharyya avatar krishbhattacharyya commented on July 22, 2024

I have not spent much time on this. But the solution is may be like this:

In the route.js reducer:
export type State = {
routes: Array,
props: ''
}

const initialState = {
routes: ['login'],
props: ''
};

And the return state is like this 👍
if (action.type === PUSH_NEW_ROUTE) {
globalNav.navigator.push({id: action.route, passProps: action.passProps});
return {
routes: [...state.routes, action.route],
props: action.passProps
};
}

if (action.type === REPLACE_ROUTE) {
globalNav.navigator.replaceWithAnimation({id: action.route, passProps: action.passProps});

    let routes = state.routes;
    routes.pop();

    return {
        routes: [...routes, action.route],
        props: action.passProps
    };
}

You should do this on another actions type also.

I got the result in asyncStorage:
{"routes":["home"],"props":"1234"}

you can pass the data like this : onPress={() => this.replaceRoute('home','1234') }

Or another process => :) hopefully it works... I have checked this.

result

from native-starter-kit.

SupriyaKalghatgi avatar SupriyaKalghatgi commented on July 22, 2024

@sudhansusingh22 @kcfgl @Proxiweb @johntom @krishbhattacharyya Check with the latest release of NSK

from native-starter-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.