Skip to content

Warning message when trying execute onHide on unmounted component #11

@caiorios

Description

@caiorios

Steps to reproduce the issue:

  1. Create a toaster with state inside a simple View.
  2. Run an event (clicking on a button for example).
  3. On event created, set the state with the desired message.
  4. After the message shows up on screen, exit the component (back button on navigator for example).
  5. After a while, a warning message shows up:

Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

Example code to reproduce the issue:

constructor(props) {
	super(props);
	this.state = {
		toast: {}
	};
}
submitAction() {
	if (this.formIsNotValid) {
		this.setState({
			toast: {
			  text: 'The form is not valid!',
			  styles: ToastStyles.error
			}
		  });
	}
}
renderMessage() {
	if (!_.isEmpty(this.state.toast)) {
		return <Toaster message={this.state.toast} />;
    }
    return <View />;
}
render() {
	return (
		<View>
			{this.renderMessage()}
			<TouchableOpacity
				style={s.buttonContainer}
				onPress={() => this.submitAction()}>
				<Text style={s.button}>Submit</Text>
			</TouchableOpacity>
		</View>
	)
}

package.json:

"dependencies": {
    "lodash": "^4.17.4",
    "moment": "^2.18.1",
    "react": "16.0.0-alpha.12",
    "react-native": "0.48.2",
    "react-native-camera": "^0.10.0",
    "react-native-config": "^0.7.0",
    "react-native-datepicker": "^1.6.0",
    "react-native-fs": "^2.8.1",
    "react-native-htmlview": "^0.12.0",
    "react-native-image-gallery": "^2.0.0",
    "react-native-navigation": "^1.1.228",
    "react-native-tab-view": "0.0.69",
    "react-native-toaster": "^1.1.2",
    "react-native-vector-icons": "^4.3.0",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0"
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions