Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay #16

Closed
grydstedt opened this issue Nov 3, 2017 · 1 comment
Closed

Delay #16

grydstedt opened this issue Nov 3, 2017 · 1 comment

Comments

@grydstedt
Copy link

Is there a way you could do a to show the component right away if it's there, but delay showing the loading spinner only for at least some time if still loading?

@gregberge
Copy link
Owner

There is an example of delay in the readme: https://github.com/smooth-code/loadable-components#delay

It defines a minimum delay to avoid loader blinking. If you want to delay the appearance of the loader, you can do it in the loader component itself, an example:

import React from 'react'

class Loader extends React.Component {
  state = { show: false }

  componentDidMount() {
    // Wait 300ms before showing it
    this.timeout = setTimeout(() => this.setState({ show: true }), 300)
  }

  componentWillUnmount() {
    clearTimeout(this.timeout)
  }

  render() {
    return this.state.show ? 'Loading' : null
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants