I am trying to make my code more dry and move if / else if statements that handles error out of the component. How can I export it and import it from another file? Example code below:
// PASSWORD ERROR HANDLING
if (!this.state.password || !this.state.password.trim()) {
this.setState({
errorPassword: "Enter your password.",
});
} else if (
this.state.password.length < 8 ||
this.state.password.trim().length < 8
) {
this.setState({
errorPassword: "Your password should have at least 8 characters long.",
});
} else if (this.state.password.trim().length > 127) {
this.setState({
errorPassword: "Your password can't be longer than 127 characters.",
});
} else {
this.setState({
errorPassword: "",
errorPasswordStatus: false,
});
}