1

I want to show the loader only when a certain period of time has elapsed. Apollo does provide a loading property but it'd show the loader instantaneously.

I was thinking of hacking something together using componentWillReceiveProps but if there's a more idiomatic way of doing this, I'd be more than happy to use that.

Mihir
  • 3,812
  • 3
  • 25
  • 29

1 Answers1

1

For this sort of thing I’d use componentDidUpdate and add in a setTimeout or perhaps a React state countdown timer. If it’s only a couple of seconds delay a setTimeout will be fine, but if it’s a long time perhaps state based countdown will be better.

JamesG
  • 2,018
  • 2
  • 28
  • 57
  • What is react state countdown timer? – Mihir Aug 14 '18 at 06:24
  • There used to be an example of one on the React docs but I can’t find it anymore. Here’s one from a SO answer. It may be a little overkill to delay a loading spinner, but you could create a new component in place and pass down props to it and have all this logic in a new component https://stackoverflow.com/q/40885923/1058586 – JamesG Aug 14 '18 at 06:27
  • Grrr. Not a fan of playing with timers. But I'll give it shot! Thanks for the pointer. I'll accept if this works out. – Mihir Aug 14 '18 at 06:37