Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Add unsetParams to navigation prop #69

Open
luissmg opened this issue Nov 21, 2018 · 2 comments
Open

Add unsetParams to navigation prop #69

luissmg opened this issue Nov 21, 2018 · 2 comments

Comments

@luissmg
Copy link

luissmg commented Nov 21, 2018

I searched a lot for this and didn't find anything regarding what I am about to write. Sorry if I missed any open issue about this.

Context

Let's consider the case where when I show some random component I set a param and I read that parameter in, let's say, the appbar.

Component setting the param:

import React from 'react';

export default class RandomComponent extends React.Component {

    ...

    componentDidMount() {
        this.props.navigation.setParams({ randomParam: 'my_value' });
    }

    ...

}

Component reading the param:

import React from 'react';

export default class RandomComponent extends React.Component {

    ...

    render() {
        const randomParam = this.props.navigation.getParam('randomParam', 'default');

        ...
    }
}

As you can see, when I don't set the param I use a default value using the getParam function on the navigation API.

Problem

In the first same component, when I unmount it I want to restore the default value. BUT I don't want to set the param again with the default value because I am using getParam form that. I want to unset that param.
Setting the param to undefined does not work.

Solution

Maybe implement a unsetParams function to unset parameters from the navigation state.

@brentvatne
Copy link
Member

seems like instead of unsetParams we should just change getParam so that it considers undefined to be empty

@luissmg
Copy link
Author

luissmg commented Dec 6, 2018

Yes, that is a good alternative. Or when you set something to undefined it unsets the parameter. Maybe your approach is better

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

2 participants