Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default params? #441

Closed
j-mendez opened this issue Feb 22, 2017 · 20 comments
Closed

Set default params? #441

j-mendez opened this issue Feb 22, 2017 · 20 comments

Comments

@j-mendez
Copy link

Is there any way to set a default param on the component itself?

@grabbou
Copy link

grabbou commented Feb 22, 2017

See https://reactnavigation.org/docs/navigators/navigation-options, section Default parameters

@grabbou grabbou closed this as completed Feb 22, 2017
@j-mendez
Copy link
Author

@grabbou I do not see this section.

@grabbou
Copy link

grabbou commented Feb 22, 2017

Try Default navigation options 😊

@j-mendez
Copy link
Author

@grabbou static navigationOptions = { state: { params: { something: false, somethingElse: false } } } did not work.

@grabbou grabbou reopened this Feb 22, 2017
@grabbou
Copy link

grabbou commented Feb 22, 2017 via email

@j-mendez
Copy link
Author

@grabbou Sure. I want to achieve this but for navigation state params since I have a statement checking to see if the prop has been passed down and set to true and need to default it to false.
screen shot 2017-02-22 at 12 57 59 pm

@j-mendez
Copy link
Author

j-mendez commented Feb 22, 2017

screen shot 2017-02-22 at 1 00 18 pm

I would like to be able to set this default value of popToStart for instance.

@ddeanto
Copy link

ddeanto commented Feb 23, 2017

This may be related to #232

@grabbou
Copy link

grabbou commented Feb 23, 2017

@jeffreymendez1993 why wouldn't const value = params.popToStart || 'defaultValue'; work?

@j-mendez
Copy link
Author

@grabbou It would work, but wouldn't you want to be able to setDefault params just how you setDefault props to have a clear vision on what the default to certain things would be. If not I guess that would work for now.

@thurt
Copy link

thurt commented Mar 1, 2017

as far as I'm aware, you currently cannot set default parameters for a scene/screen. but seems like there is a good argument for adding them

@j-mendez
Copy link
Author

j-mendez commented Mar 6, 2017

@thurt I think this should be added as for this makes code clean and easy to read.

@dantman
Copy link

dantman commented Apr 18, 2017

This is especially important for things like the DrawerNavigator where routes are not opened by a navigator.navigate(..., params) call within the app, but instead are navigated to by the DrawerRouter without any params.

Without default params it's not possible (at least not without fudging things using the routeName) to have a bunch of drawer items with the same screen but different params, like:

DrawerNavigator({
  Inbox: {
    screen: MessageList,
    params: {
      filter: {
        archived: false
      }
    },
  },
  Archives: {
    screen: MessageList,
    params: {
      filter: {
        archived: true
      }
    },
  },
  AllMessages: {
    screen: MessageList,
  },
});

@j-mendez
Copy link
Author

@dantman that would be perfect

@ntkzwane
Copy link

I share the same sentiments with @dantman, except my scenario involves use of the TabNavigator. I see you made reference to #838, however this wouldn't be the cleanest solution in my opinion.

@0x5e
Copy link

0x5e commented Aug 25, 2017

Same problems with @dantman . Same screen with different params.

@jiyarong
Copy link

jiyarong commented Oct 8, 2017

Has the problem been solved?

@brentvatne
Copy link
Member

hi there! I moved this feature request to canny, as it's our new home for feature requests: https://react-navigation.canny.io/feature-requests/p/set-default-params-in-a-screen-component

issues are now only for bugs

@brentvatne
Copy link
Member

brentvatne commented Mar 6, 2018

where you use the param, you can do this:

this.props.navigation.getParam('name', defaultValueHere)

if you think this api isn't good enough then please open a rfc to discuss further

@react-navigation react-navigation locked and limited conversation to collaborators Mar 6, 2018
@brentvatne
Copy link
Member

the api that @dantman suggested above was implemented in react-navigation/core#11

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants