Skip to content

Commit 15718fd

Browse files
authored
Merge pull request #1 from diegoblattner/fix/redux-initia-state
fix(initial-state): Fix blink after SSR
2 parents 56d05a9 + 1a583bb commit 15718fd

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/components/Countries/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export default class Countries extends Component {
1515
}
1616

1717
componentDidMount() {
18-
this.props.fetchCountries();
18+
const { countries: { data } } = this.props;
19+
20+
if (!data || data.length === 0) {
21+
this.props.fetchCountries();
22+
}
1923
}
2024

2125

src/store.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
import { applyMiddleware, createStore } from "redux";
1+
import { applyMiddleware, createStore, compose } from "redux";
22
import rootReducer from "./reducers";
33
import reduxThunk from "redux-thunk";
44

5-
export default createStore(rootReducer, {}, applyMiddleware(reduxThunk));
5+
let composeEnhancers = compose;
6+
let preloadedState = {};
7+
8+
if (typeof window !== 'undefined') {
9+
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
10+
preloadedState = window.INITIAL_STATE || {};
11+
delete window.INITIAL_STATE;
12+
}
13+
14+
export default createStore(
15+
rootReducer,
16+
preloadedState,
17+
composeEnhancers(
18+
applyMiddleware(reduxThunk),
19+
),
20+
);

0 commit comments

Comments
 (0)