-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Add Ready component to handle loading across pages. #242
Conversation
It would be great if this assisted in animations between pages too... |
From the original issue:
Keep in mind that the "fetch the data" part is optional. One can go ahead and do: getInitialProps ({ req }) {
if (req) {
// get data now
} else {
// get data on `componentDidMount`
}
}) I agree that there might be "Loading" wants to do while we wait on that. But I wonder if it could be handled better with something like: <Link href="/test" onClick={ () => this.setState({ loading: true }) }>
<a>Let's go to another page</a>
</Link> |
In other words, maybe we have to make |
Okay. Basically, you mean loading stuff is out of the scope of Next. Let' say we have a lot of Links elements on the page. Then we have to add hooks for many links. Practically, I'd like to add this loading capability into a layout in my app. May be we could expose a |
@arunoda in that instance couldn't you just create a new component that just wraps |
@arunoda the problem of adding hooks to many links is very trivially solved: import Link from './my-link'
export default () => (
<p>Hi there, my fancy <Link><a>here</a></Link></p>
) this link could do a lot of interesting things that are shared across pages. Not least of which is showing a spinner or Medium-style bar for transitions between pages: https://twitter.com/rauchg/status/797577535370317825 for which I would love to have an example on the wiki. |
I suspect that creating that example would force us to design the proper hooks on |
Okay guys, yep. I got the way we need to this via In order to do that, I hope we need one last feature for Link (or a way to to get it from somewhere else in a nice way). We can do it by hooking into the History API, or React components. But adding good API with links makes sense a lot. Here's an suggestion: const startLoading = () => console.log("Start Loading");
const stopLoading = () => console.log("Stop Loading");
<Link onClick={startLoading} onStop={stopLoading}/> |
Guys, I think we could close this PR. |
As you can see you're commenting on a closed pull-request, not a merged one. So this proposal was never added to Next.js. You're probably looking for https://github.com/zeit/next.js#3-with-no-ssr |
Fixes #238
Basically this allows us to show a loading screen when switching between pages.
Here's how to use this: