Answer the question
In order to leave comments, you need to log in
What logic should be here?
After sending the data to the backend, a response comes from the backend. You need to display this answer for 4-5 seconds. This is how it works on Instagram. Looks like this.
This is the page for sending an email to reset your password.
Question one: Do you think it would be the right decision if I write all this code in the component file?
I have a whole ecosystem to enter and register. Everything works through Redux.
Question two: What logic should be here? Somehow remove the message from the state after 4-5 seconds?
( {this.state.message && <Alert message={this.state.message}/>} )
Answer the question
In order to leave comments, you need to log in
in the parent element in the state, let it be { showAlert: false, alertMessage: 'blabla' } <Alert show={this.state.showAlert} />
let it be always and by default hidden
when necessary, then
this.setState({ showAlert: true, alertMessage: responseFromServer })
setTimeout( () => setState({ showAlert: false }), 5000 )
why don't you use any Toast instead of Alert?
https://github.com/fkhadra/react-toastify
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question