Skip to content

Commit 208efae

Browse files
committed
Don't depend on console and don't warn in production builds
1 parent 9937837 commit 208efae

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/components/Provider.js

+29-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
const { Component, PropTypes, Children } = require('react')
22
const storeShape = require('../utils/storeShape')
33

4-
let didWarnAboutReceivingStore = false
5-
function warnAboutReceivingStore() {
6-
if (didWarnAboutReceivingStore) {
7-
return
4+
if (process.env.NODE_ENV !== 'production') {
5+
let didWarnAboutReceivingStore = false
6+
/* eslint-disable no-var */
7+
var warnAboutReceivingStore = function () {
8+
/* eslint-enable no-var */
9+
if (didWarnAboutReceivingStore) {
10+
return
11+
}
12+
didWarnAboutReceivingStore = true
13+
14+
/* eslint-disable no-console */
15+
if (typeof console !== 'undefined' && typeof console.error === 'function') {
16+
console.error(
17+
'<Provider> does not support changing `store` on the fly. ' +
18+
'It is most likely that you see this error because you updated to ' +
19+
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
20+
'automatically. See https://github.com/rackt/react-redux/releases/' +
21+
'tag/v2.0.0 for the migration instructions.'
22+
)
23+
}
24+
/* eslint-disable no-console */
825
}
9-
10-
didWarnAboutReceivingStore = true
11-
console.error( // eslint-disable-line no-console
12-
'<Provider> does not support changing `store` on the fly. ' +
13-
'It is most likely that you see this error because you updated to ' +
14-
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
15-
'automatically. See https://github.com/rackt/react-redux/releases/' +
16-
'tag/v2.0.0 for the migration instructions.'
17-
)
1826
}
1927

2028
class Provider extends Component {
@@ -27,19 +35,21 @@ class Provider extends Component {
2735
this.store = props.store
2836
}
2937

30-
componentWillReceiveProps(nextProps) {
38+
render() {
39+
let { children } = this.props
40+
return Children.only(children)
41+
}
42+
}
43+
44+
if (process.env.NODE_ENV !== 'production') {
45+
Provider.prototype.componentWillReceiveProps = function (nextProps) {
3146
const { store } = this
3247
const { store: nextStore } = nextProps
3348

3449
if (store !== nextStore) {
3550
warnAboutReceivingStore()
3651
}
3752
}
38-
39-
render() {
40-
let { children } = this.props
41-
return Children.only(children)
42-
}
4353
}
4454

4555
Provider.propTypes = {

0 commit comments

Comments
 (0)