REACTJS redirecting + 5 second timeout

Viewed 2956

Im fairly new to reactjs and can't figure something out. I am trying to build a webpage that redirects after 5 seconds but can't seem to figure out how. If anyone has any tips for me where I can find out how to do this it would be really appreciated.

Thanks :)

2 Answers

That's something you can do with plain JavaScript. It would look like this:

setTimeout(function() {
  window.location.replace('some-url');
}, 5000);

Depending on when you want to fire that, you can put it in some component's "lifecycle method" or even just simply add it at the beginning of your JS file or in 'DOMContentLoaded' event.

Related