0
  • I created a react app and implemented two routes.

  • The Page on '/' shows a welcome message and /pageone shows the other page.

  • i have button in homepage( "/" ) which is wrapped with link to="/pageone".

  • I have a function onClose = () => {this.setState({visible:false,});} i want it to run first after that only i want to change my route onclicking/

how to achieve this? is there any way to write a function that runs this onClose function and then route to the link?

1
  • Write a function which run on button click, first include the onclose function in it then use react router redirect to change the path Commented Sep 18, 2019 at 5:31

1 Answer 1

1

Your query is regarding the callback function, so you can use the callback function in this.setState just like this

this.setState({
    visible:false 
},() => {
    /// this part will be executed only after the visible is set to false
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.