Skip to content

Commit b523aa4

Browse files
dlivgaearon
authored andcommitted
Issue 1743 (reduxjs#1770)
* rename createStore param `initialState` to `preloadedState` * rename configureStore param `initialState` to `preloadedState` * rename `window.__INITIAL_STATE__` in examples and docs rename window.__INITIAL_STATE__ to window.__PRELOADED_STATE__
1 parent c90684f commit b523aa4

File tree

19 files changed

+57
-57
lines changed

19 files changed

+57
-57
lines changed

docs/Glossary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ See the complete [store API reference](api/Store.md#dispatch) for more details.
114114
## Store creator
115115

116116
```js
117-
type StoreCreator = (reducer: Reducer, initialState: ?State) => Store
117+
type StoreCreator = (reducer: Reducer, preloadedState: ?State) => Store
118118
```
119119
120-
A store creator is a function that creates a Redux store. Like with dispatching function, we must distinguish the base store creator, [`createStore(reducer, initialState)`](api/createStore.md) exported from the Redux package, from store creators that are returned from the store enhancers.
120+
A store creator is a function that creates a Redux store. Like with dispatching function, we must distinguish the base store creator, [`createStore(reducer, preloadedState)`](api/createStore.md) exported from the Redux package, from store creators that are returned from the store enhancers.
121121
122122
## Store enhancer
123123

docs/advanced/ExampleRedditAPI.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ import rootReducer from './reducers'
170170

171171
const loggerMiddleware = createLogger()
172172

173-
export default function configureStore(initialState) {
173+
export default function configureStore(preloadedState) {
174174
return createStore(
175175
rootReducer,
176-
initialState,
176+
preloadedState,
177177
applyMiddleware(
178178
thunkMiddleware,
179179
loggerMiddleware

docs/api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This section documents the complete Redux API. Keep in mind that Redux is only c
66

77
### Top-Level Exports
88

9-
* [createStore(reducer, [initialState])](createStore.md)
9+
* [createStore(reducer, [preloadedState])](createStore.md)
1010
* [combineReducers(reducers)](combineReducers.md)
1111
* [applyMiddleware(...middlewares)](applyMiddleware.md)
1212
* [bindActionCreators(actionCreators, dispatch)](bindActionCreators.md)

docs/api/applyMiddleware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export default connect(
232232

233233
const store = createStore(
234234
reducer,
235-
initialState,
235+
preloadedState,
236236
applyMiddleware(...middleware)
237237
)
238238
```

docs/api/createStore.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `createStore(reducer, [initialState], [enhancer])`
1+
# `createStore(reducer, [preloadedState], [enhancer])`
22

33
Creates a Redux [store](Store.md) that holds the complete state tree of your app.
44
There should only be a single store in your app.
@@ -7,7 +7,7 @@ There should only be a single store in your app.
77

88
1. `reducer` *(Function)*: A [reducing function](../Glossary.md#reducer) that returns the next [state tree](../Glossary.md#state), given the current state tree and an [action](../Glossary.md#action) to handle.
99

10-
2. [`initialState`] *(any)*: The initial state. You may optionally specify it to hydrate the state from the server in universal apps, or to restore a previously serialized user session. If you produced `reducer` with [`combineReducers`](combineReducers.md), this must be a plain object with the same shape as the keys passed to it. Otherwise, you are free to pass anything that your `reducer` can understand.
10+
2. [`preloadedState`] *(any)*: The initial state. You may optionally specify it to hydrate the state from the server in universal apps, or to restore a previously serialized user session. If you produced `reducer` with [`combineReducers`](combineReducers.md), this must be a plain object with the same shape as the keys passed to it. Otherwise, you are free to pass anything that your `reducer` can understand.
1111

1212
3. [`enhancer`] *(Function)*: The store enhancer. You may optionally specify it to enhance the store with third-party capabilities such as middleware, time travel, persistence, etc. The only store enhancer that ships with Redux is [`applyMiddleware()`](./applyMiddleware.md).
1313

docs/recipes/ServerRendering.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ app.use(handleRender)
5353

5454
// We are going to fill these out in the sections to follow
5555
function handleRender(req, res) { /* ... */ }
56-
function renderFullPage(html, initialState) { /* ... */ }
56+
function renderFullPage(html, preloadedState) { /* ... */ }
5757

5858
app.listen(port)
5959
```
@@ -83,23 +83,23 @@ function handleRender(req, res) {
8383
)
8484

8585
// Grab the initial state from our Redux store
86-
const initialState = store.getState()
86+
const preloadedState = store.getState()
8787

8888
// Send the rendered page back to the client
89-
res.send(renderFullPage(html, initialState))
89+
res.send(renderFullPage(html, preloadedState))
9090
}
9191
```
9292

9393
### Inject Initial Component HTML and State
9494

95-
The final step on the server side is to inject our initial component HTML and initial state into a template to be rendered on the client side. To pass along the state, we add a `<script>` tag that will attach `initialState` to `window.__INITIAL_STATE__`.
95+
The final step on the server side is to inject our initial component HTML and initial state into a template to be rendered on the client side. To pass along the state, we add a `<script>` tag that will attach `preloadedState` to `window.__PRELOADED_STATE__`.
9696

97-
The `initialState` will then be available on the client side by accessing `window.__INITIAL_STATE__`.
97+
The `preloadedState` will then be available on the client side by accessing `window.__PRELOADED_STATE__`.
9898

9999
We also include our bundle file for the client-side application via a script tag. This is whatever output your bundling tool provides for your client entry point. It may be a static file or a URL to a hot reloading development server.
100100

101101
```js
102-
function renderFullPage(html, initialState) {
102+
function renderFullPage(html, preloadedState) {
103103
return `
104104
<!doctype html>
105105
<html>
@@ -109,7 +109,7 @@ function renderFullPage(html, initialState) {
109109
<body>
110110
<div id="root">${html}</div>
111111
<script>
112-
window.__INITIAL_STATE__ = ${JSON.stringify(initialState)}
112+
window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState)}
113113
</script>
114114
<script src="/static/bundle.js"></script>
115115
</body>
@@ -124,7 +124,7 @@ function renderFullPage(html, initialState) {
124124
125125
## The Client Side
126126

127-
The client side is very straightforward. All we need to do is grab the initial state from `window.__INITIAL_STATE__`, and pass it to our [`createStore()`](../api/createStore.md) function as the initial state.
127+
The client side is very straightforward. All we need to do is grab the initial state from `window.__PRELOADED_STATE__`, and pass it to our [`createStore()`](../api/createStore.md) function as the initial state.
128128

129129
Let’s take a look at our new client file:
130130

@@ -139,10 +139,10 @@ import App from './containers/App'
139139
import counterApp from './reducers'
140140

141141
// Grab the state from a global injected into server-generated HTML
142-
const initialState = window.__INITIAL_STATE__
142+
const preloadedState = window.__PRELOADED_STATE__
143143

144144
// Create Redux store with initial state
145-
const store = createStore(counterApp, initialState)
145+
const store = createStore(counterApp, preloadedState)
146146

147147
render(
148148
<Provider store={store}>
@@ -182,10 +182,10 @@ function handleRender(req, res) {
182182
const counter = parseInt(params.counter, 10) || 0
183183

184184
// Compile an initial state
185-
let initialState = { counter }
185+
let preloadedState = { counter }
186186

187187
// Create a new Redux store instance
188-
const store = createStore(counterApp, initialState)
188+
const store = createStore(counterApp, preloadedState)
189189

190190
// Render the component to a string
191191
const html = renderToString(
@@ -202,7 +202,7 @@ function handleRender(req, res) {
202202
}
203203
```
204204

205-
The code reads from the Express `Request` object passed into our server middleware. The parameter is parsed into a number and then set in the initial state. If you visit [http://localhost:3000/?counter=100](http://localhost:3000/?counter=100) in your browser, you’ll see the counter starts at 100. In the rendered HTML, you’ll see the counter output as 100 and the `__INITIAL_STATE__` variable has the counter set in it.
205+
The code reads from the Express `Request` object passed into our server middleware. The parameter is parsed into a number and then set in the initial state. If you visit [http://localhost:3000/?counter=100](http://localhost:3000/?counter=100) in your browser, you’ll see the counter starts at 100. In the rendered HTML, you’ll see the counter output as 100 and the `__PRELOADED_STATE__` variable has the counter set in it.
206206

207207
### Async State Fetching
208208

@@ -245,10 +245,10 @@ function handleRender(req, res) {
245245
const counter = parseInt(params.counter, 10) || apiResult || 0
246246

247247
// Compile an initial state
248-
let initialState = { counter }
248+
let preloadedState = { counter }
249249

250250
// Create a new Redux store instance
251-
const store = createStore(counterApp, initialState)
251+
const store = createStore(counterApp, preloadedState)
252252

253253
// Render the component to a string
254254
const html = renderToString(

examples/async/store/configureStore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import thunkMiddleware from 'redux-thunk'
33
import createLogger from 'redux-logger'
44
import rootReducer from '../reducers'
55

6-
export default function configureStore(initialState) {
6+
export default function configureStore(preloadedState) {
77
const store = createStore(
88
rootReducer,
9-
initialState,
9+
preloadedState,
1010
applyMiddleware(thunkMiddleware, createLogger())
1111
)
1212

examples/real-world/store/configureStore.dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import api from '../middleware/api'
55
import rootReducer from '../reducers'
66
import DevTools from '../containers/DevTools'
77

8-
export default function configureStore(initialState) {
8+
export default function configureStore(preloadedState) {
99
const store = createStore(
1010
rootReducer,
11-
initialState,
11+
preloadedState,
1212
compose(
1313
applyMiddleware(thunk, api, createLogger()),
1414
DevTools.instrument()

examples/real-world/store/configureStore.prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import thunk from 'redux-thunk'
33
import api from '../middleware/api'
44
import rootReducer from '../reducers'
55

6-
export default function configureStore(initialState) {
6+
export default function configureStore(preloadedState) {
77
return createStore(
88
rootReducer,
9-
initialState,
9+
preloadedState,
1010
applyMiddleware(thunk, api)
1111
)
1212
}

examples/todomvc/store/configureStore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createStore } from 'redux'
22
import rootReducer from '../reducers'
33

4-
export default function configureStore(initialState) {
5-
const store = createStore(rootReducer, initialState)
4+
export default function configureStore(preloadedState) {
5+
const store = createStore(rootReducer, preloadedState)
66

77
if (module.hot) {
88
// Enable Webpack hot module replacement for reducers

0 commit comments

Comments
 (0)