janoist1 / universal-react-redux-starter-kit

Get started with React, Redux, and React-Router! - With universal rendering!
MIT License
63 stars 9 forks source link

Is there a way to wait for API response before server will render a page? #14

Open kuatro opened 8 years ago

kuatro commented 8 years ago

Hello! I found that server isn't waiting for async API response, and sends blank components to front-end.

janoist1 commented 8 years ago

Hi! I'll have a look at it soon, probably tomorrow.

kuatro commented 8 years ago

What do you think about this approach? bananaoomarang/isomorphic-redux

The only confusing thing for me is adding a needs array to each container.

janoist1 commented 8 years ago

I'll check it later in the weekend and come back to you. Thanks for the link.

janoist1 commented 8 years ago

I've checked it. It's a nice solution, I might implement it into this starter kit once I have some time. ;-)

bodyno commented 8 years ago

also have the same question

kuatro commented 8 years ago

@bodyno I think we could help @janoist1. Currently I'm working on integration redux-saga in this boilerplate, but I haven't much free time. Could you implement something like the example that I've posted above?

bodyno commented 8 years ago

@kuatro I'm not so familiar with the universal react. Please tell me how to call dispatch action at server side.

janoist1 commented 8 years ago

It looks like I'll have some time in the upcoming weekend, will try to implement an async example and do some general updates. ;)

bodyno commented 8 years ago

:+1: :+1: :+1:

bodyno commented 8 years ago

@janoist1 Please just give me some train of thought how to call dispatch action at server side

janoist1 commented 7 years ago

@bodyno I'm not sure what you wanna achieve but guessing you want a point where you can initiate your (async) API request. I chose route onEnter callback as starting point:

import Weather from './containers/WeatherContainer'
import { fetchWeatherData } from './modules/weather'

export default store => ({
  path: 'weather',
  component: Weather,
  onEnter: () => {
    // async get weather data
    store.dispatch(fetchWeatherData())
  }
})

I'm working on an async example that runs on server side. I'm not far from getting it done. ;-)

peterpme commented 7 years ago

@kuatro if you can show me exactly what needs to be done, I'm personally interested in fixing this and don't mind submitting a PR to make it happen

kuatro commented 7 years ago

Hey, @peterpme . As I understood, when you build an isomorphic React/Redux app, you need to implement your own promise middleware to resolve all API requests on server-side. I've sent a link above: bananaoomarang/isomorphic-redux

peterpme commented 7 years ago

@janoist1 mind closing out this issue and direct folks to #19?