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

Placeholder loading app while fetching data #2985

Closed
dcatanzaro opened this issue Sep 25, 2017 · 12 comments
Closed

Placeholder loading app while fetching data #2985

dcatanzaro opened this issue Sep 25, 2017 · 12 comments

Comments

@dcatanzaro
Copy link

Hi.

Im using NextJS for a big project and I want to add a placeholder loading while fetching data.

Example:
image

Currently NextJS use fetch in getInitialProps and wait to fetch all data to show de render.

Is there a way to show the basic render with placeholder loading and in the background do the fetch?

Thanks!

@ragingwind
Copy link
Contributor

How about https://github.com/zeit/next.js#router-events

@markozxuu
Copy link
Contributor

@dcatanzaro If the doubt was resolved, I suggest closing the subject 😸

@azza85
Copy link

azza85 commented Sep 26, 2017

@dcatanzaro I have it working in this issue, #2981 I am having a few issues on a dynamic level page but may work for what you are looking for.

@dcatanzaro
Copy link
Author

Thanks! I will see both.

@JustasPolis
Copy link

If you want to show some loading/placeholders just dont fetch on SSR, use componentDidMount and fetch when client kicks in and while fetching show your placeholder :)

@dcatanzaro
Copy link
Author

I'm trying to continue using SSR, and when it comes from de client-side use componentDidMount!

Thanks!.

@timneutkens
Copy link
Member

Like @JustasPolis said when you use componentDidMount to fetch you can render the placeholder server side 👍

@yann-yinn
Copy link

Hello ! Can someone provide an example of this ? I want my page to display "loading ..." until getInitialProps() Promise is resolved; so it is basically the same need than the one described in this issue.

Should I use router events ? is there an example somewhere on how this has to be done ? Should i use a store to update a "pageLoading" variable ?

Should I use componentDidMount ? I dont understand this suggestion, as i guess i will loose SSR if i use this method...

Any help appreciated :)

@timneutkens
Copy link
Member

@yann-yinn
Copy link

yann-yinn commented Oct 8, 2017

@timneutkens definitely does, thanks !
So the answer is : use Router events. The above example is using nprogress to display a progress bar at the top of the page and that works great, but we can do anything we want this way...

Router.onRouteChangeStart = (url) => NProgress.start()
Router.onRouteChangeComplete = () => NProgress.done()
Router.onRouteChangeError = () => NProgress.done()

@timneutkens
Copy link
Member

👌 Happy it helped 😄

There's an example for that! - Tim Neutkens

@lock
Copy link

lock bot commented May 10, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants