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

When is it "Safe" to clear application state after calling reset or popTo #2926

Closed
ChristianTucker opened this issue Mar 9, 2018 · 3 comments

Comments

@ChristianTucker
Copy link

This is a question.

I'm trying to implement the logout function in my application without pushing the authentication screen back onto my navigation stack, instead I wish to replace the navigation stack with the authentication screen. ( I've been really careful to not push screens onto the stack without popping them off, in order to only keep a few items in the stack at any given time )

From the documentation Actions.reset(...)

Clears the routing stack and pushes the scene into the first index. No transition will occur.

Once calling Actions.reset I then try to clear my Redux state that's used in my Profile screen. However, even though I've reset the navigation stack the application crashes with undefined variable errors from the Profile (as a result of clearing the redux state on logout).

I've gone through the documentation thoroughly in order to try to find a way to determine when a navigation transition is completed, but I haven't found anything.

The way I found to do this was to use componentWillUnmount on my application's <Tabs /> component (Which is the root scene of the component when a user is authenticated) and dispatch from there in order to clear the state.

This seems to be working, but it also requires me to separate my code. Is there any way to do this in a more clean and localized manner? For example:

Actions.reset('componentKey').on('completed', () => {
    // Handle cleanup code 
});

Which would be called after all of the components in the stack have been unmounted.

@asciifaceman
Copy link
Contributor

I would be curious to think around and see if Actions can return promises so you could do something like

Actions.reset('componentKey')
.then((promise) => {
    if (promise) {
        // Do a thing
    }
})

But I haven't thought this out entirely.

@arnsa
Copy link

arnsa commented Mar 31, 2018

@ChristianTucker @asciifaceman you could do something like this:

InteractionManager.runAfterInteractions(() => { // clear state here });

@aksonov
Copy link
Owner

aksonov commented Aug 8, 2018

I guess @arnsa is right

@aksonov aksonov closed this as completed Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants