Talor-A / react-native-message-bar

A notification bar alert displayed at the top of the screen for react-native
MIT License
55 stars 27 forks source link

Can only Update a mounting and mounted component #22

Closed lgupta54 closed 6 years ago

lgupta54 commented 6 years ago

Issue: Can only Update a mounting and mounted component. This usually means you called setState or the forceUpdate on the unmounted component. This is a no-op. Please check the code for the MessageBar Component.

Registered and unregistered MessageBarManager as is it is shown in demo. But when coming back from navigated screen, this warning shows up and Alert message does not shows then.

Talor-A commented 6 years ago

this is a problem with react-navigation, not this library. screens aren't unmounted when navigating away from them. to fix this put your message bar component outside of the stacknavigator component.

malonguwa commented 6 years ago

@Talor-A Could you mind to give a example about outside of stacknavigator component? Cos my app is using StackNavigator at App.js as the root component,

App.js

 render() {
            return <LoginStackNavigator screenProps={screenProps} />;
   }

LoginStackNavigator.js

export const LoginStackNavigator = StackNavigator({
    LoginScreen: {
        screen: LoginScreen,
        navigationOptions : {
            header:null
        }
    }, .........
}

How to put message bar component outside of the stacknavigator ? And what should I do in different Screen inside the StackNavigator to use the MesageAlert?

Thanks a lot

malonguwa commented 6 years ago

I fix it~ Thanks @Talor-A , I think I got what you mean~

I solved it by doing this, in App.js

 render() {
            return <View style={{flex:1, backgroundColor:"green"}}>
                <LoginStackNavigator screenProps={screenProps} />
                <MessageBarAlert ref="alertLogin"/>
            </View>;
}