Comments (5)
+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.
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.
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.
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.
from native-starter-kit.
@sudhansusingh22 @kcfgl @Proxiweb @johntom @krishbhattacharyya Check with the latest release of NSK
from native-starter-kit.
Related Issues (20)
- ERROR Error watching file for changes: EMFILE HOT 2
- How to rename this project HOT 12
- Disable drawer gesture for Drawer HOT 5
- StackNav variable in MainStackRouter.js is promotion to global HOT 1
- after update react native 0.46.4,error out. HOT 4
- (node:404) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead. HOT 1
- react version problem HOT 5
- yarn install error HOT 4
- SDK Build Tools Version Used by Starter Kit Out of Date HOT 1
- How to Retrieve data from AsyncStorage
- Codepush crashes on Android but works on iOS
- Login button's first press not fired HOT 1
- What does the @ symbol do in javascript imports? HOT 2
- Drawer Navigating Animation HOT 8
- Picker itemTextStyle,itemTextStyle,textStyle not working HOT 1
- Could not determine java version from '10.0.1'. ??
- How i run this project on expo ? HOT 2
- var oldJsCodeLocationAssignmentStatement = appDelegateContents.match(/(jsCodeLocation = .*)/)[1]; HOT 1
- Update?
- Unable to resolve module "color" from "js\themes\base-theme.js"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from native-starter-kit.