olebedev / go-starter-kit

[abandoned] Golang isomorphic react/hot reloadable/redux/css-modules/SSR starter kit
Other
2.82k stars 357 forks source link

Resolving promises in onEnter() #74

Open tanis2000 opened 7 years ago

tanis2000 commented 7 years ago

Is there any way to resolve promises in onEnter() when calling it from the server? I'd like my components to fetch some data before rendering but I'm facing an issue.

If I add the fetch data stuff as a promise with something along the line of store.dispatch(loadData()); it works fine on the client but since it returns a Promise, it doesn't work on the server.

On the other hand if I move the code of my loadData function directly into onEnter it does get called on the server as well as I'm calling fetch() directly instead of returning it, but then React complains that the HTML being created on the client is different from the one on the server.

Is there a smart way to accomplish this?