Slide 43
Slide 43 text
// fetchData.js
export default fetchCall => Component => {
Component.onEnter = (store) =>
(nextState, replace, callback) => {
const result = fetchCall(
store.dispatch,
store.getState(),
nextState,
replace) || Promise.resolve(true);
if(typeof window === 'undefined') {
result.then(() => callback())
.catch((error) => callback(error))
} else {
callback();
}
}
return Component;
}