Skip to content

Commit f957b9f

Browse files
committed
update getState error message
1 parent 7507eae commit f957b9f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/createStore.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export default function createStore(reducer, initialState, enhancer) {
7272
*/
7373
function getState() {
7474
if (isDispatching) {
75-
throw new Error('Reducers may not access store state.')
75+
throw new Error(
76+
'You may not call store.getState() while the reducer is executing.' +
77+
'The reducer has already received the state as an argument.' +
78+
'Pass it down from the top reducer instead of reading it from the store.'
79+
)
7680
}
7781

7882
return currentState
@@ -115,7 +119,7 @@ export default function createStore(reducer, initialState, enhancer) {
115119
ensureCanMutateNextListeners()
116120
nextListeners.push(listener)
117121

118-
return function unsubscribe() {
122+
return function unsubscribe() {
119123
if (!isSubscribed) {
120124
return
121125
}

test/createStore.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe('createStore', () => {
464464

465465
expect(() =>
466466
store.dispatch(getStateInMiddle(store.getState.bind(store)))
467-
).toThrow(/may not access store state/)
467+
).toThrow(/You may not call store.getState()/)
468468
})
469469

470470
it('does not allow subscribe() from within a reducer', () => {

0 commit comments

Comments
 (0)