question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data fetching in 1.0.0’s onEnter — possible? Good idea in the first place?

See original GitHub issue

I’m wondering what the recommended practice for fetching data necessary for rendering a route is in 1.0.0. Let’s say a user browses to /post/123, I’d like to make a call to my API to make sure that this Post is in my stores and ready to go.

At the moment I’ve been firing these API actions in componentWillMount, but part of me wonders if it would be better to do this kind of work in 1.0.0 Route’s onEnter? I can’t get that to work as my API actions return Promises and I can’t see anyway to trigger a transition manually, but then again, how would I display any visual indication that the app is loading something this way?

To sum it up, can onEnter be used to defer a transition until a promise is fulfilled, and is this a good idea in the first place? Thanks very much.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

14reactions
mjacksoncommented, Jun 23, 2015

No, do not fetch data in onEnter. This is always a bad idea because the UI will not be responsive while you’re fetching data.

Please see the AsyncProps code (still experimental) for some ideas we have around how to do this properly.

8reactions
freshtoniccommented, Oct 7, 2015

@mjackson IMHO having top-level components load their own data is both more complex from a programming perspective (because at least two states are needed: loading/loaded) and transitioning before data is loaded is janky as components all resize to accommodate data as it arrives. I’d much rather have route transitions take a little longer. The perception of slowness can be solved with visual feedback such as loading indicators.

If it is indeed possible to do async data loading with onEnter then I suggest that you retain the name and not rename it 😃 Might I also suggest that this becomes an officially supported use case - instead of advocating not data loading in onEnter how about just explaining the trade-offs? Not everybody shares the opinion that data loading must not be async.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data fetching in 1.0.0's onEnter — possible? Good idea in the ...
No, do not fetch data in onEnter . This is always a bad idea because the UI will not be responsive while you're...
Read more >
react-router-manager - npm
This module is heavily based on react-router-config and expands on the same concept. The goal is to create a one stop solution to...
Read more >
A comprehensive guide to data fetching in React
We'll demonstrate how to fetch data in React, complete with code examples, and introduce a handful of approaches to help you determine the...
Read more >
4.8.6 The video element — HTML5 (Edition for Web Authors) - W3C
The video element is a media element whose media data is ostensibly video data ... the first non-blank frames) that gives the user...
Read more >
Guide: UI-Router 1.0 Migration
We took the concept of “Future State” from UI-Router Extras and baked it into UI-Router as of 1.0.0-beta.2. A future state is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found