Skip to content

Commit 0fa1c84

Browse files
committed
Configure and set Redux Store
This involves creating a store instance with proper setup (redux thunk middleware is passed) and setting created instance as a default store for the application by means of <Provider /> component.
1 parent 6f65c69 commit 0fa1c84

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/index.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { BrowserRouter } from 'react-router-dom';
4+
import { Provider } from 'react-redux';
45

56
import App from './components/App';
7+
import store from './store';
68

79
ReactDOM.render(
810
(
9-
<BrowserRouter>
10-
<App />
11-
</BrowserRouter>
11+
<Provider store={store}>
12+
<BrowserRouter>
13+
<App />
14+
</BrowserRouter>
15+
</Provider>
1216
), document.getElementById('root'),
1317
);

src/store/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as redux from 'redux';
2+
import thunk from 'redux-thunk';
3+
4+
import reducer from '../reducers';
5+
6+
// Redux Thunk middleware allows you to write action creators that return a
7+
// function instead of an action. The thunk can be used to delay the dispatch
8+
// of an action, or to dispatch only if a certain condition is met. The former
9+
// is the case for XSnippet Web since we need to fetch data via HTTP API first
10+
// and then dispatch it to store.
11+
export default redux.createStore(reducer, redux.applyMiddleware(thunk));

0 commit comments

Comments
 (0)