https://github.com/casprwang/gatsby-using-redux-example
issuing an example
https://github.com/casprwang/gatsby-using-redux-example
Last synced: about 1 month ago
JSON representation
issuing an example
- Host: GitHub
- URL: https://github.com/casprwang/gatsby-using-redux-example
- Owner: casprwang
- Created: 2017-11-28T01:15:53.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-28T06:38:37.000Z (almost 8 years ago)
- Last Synced: 2025-02-02T01:41:36.124Z (8 months ago)
- Language: JavaScript
- Size: 184 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redux
https://using-redux.gatsbyjs.org/
Gatsby example site that shows use of redux.
### Original version
[https://github.com/gatsbyjs/gatsby/tree/master/examples/using-redux](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-redux)### Diff
in `src/state/createStore.js`original
```js
import { createStore as reduxCreateStore } from "redux"const reducer = (state, action) => {
if (action.type === `INCREMENT`) {
return Object.assign({}, state, {
count: state.count + 1,
})
}
return state
}const initialState = { count: 0 }
const createStore = () => reduxCreateStore(reducer, initialState)
export default createStore
```in here
```js
import { combineReducers, createStore as reduxCreateStore } from "redux"const initialState = { count: 0 }
const reducer = (state={}, action) => {
if (action.type === `INCREMENT`) {
return Object.assign({}, state, {
count: state.count + 1,
})
}
return state
}const createStore = () => reduxCreateStore(combineReducers({reducer}), initialState)
export default createStore
```final version
```js
import { combineReducers, createStore as reduxCreateStore } from 'redux'const reducer = (state = 0, action) => {
if (action.type === `INCREMENT`) {
return state + 1
}
return state
}const root = combineReducers({
count: reducer,
})const createStore = () => reduxCreateStore(root)
export default createStore
```