mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-27 00:19:55 +03:00
Wrap connected monitor in Provider and ReactReduxContext for react-redux@6
This commit is contained in:
parent
b80cc9e5b9
commit
fef81b1618
|
@ -1,8 +1,24 @@
|
|||
import React, { Children, Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import { connect, Provider, ReactReduxContext } from 'react-redux';
|
||||
import instrument from 'redux-devtools-instrument';
|
||||
|
||||
function logError(type) {
|
||||
if (type === 'NoStore') {
|
||||
console.error(
|
||||
'Redux DevTools could not render. You must pass the Redux store ' +
|
||||
'to <DevTools> either as a "store" prop or by wrapping it in a ' +
|
||||
'<Provider store={store}>.'
|
||||
);
|
||||
} else {
|
||||
console.error(
|
||||
'Redux DevTools could not render. Did you forget to include ' +
|
||||
'DevTools.instrument() in your store enhancer chain before ' +
|
||||
'using createStore()?'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default function createDevTools(children) {
|
||||
const monitorElement = Children.only(children);
|
||||
const monitorProps = monitorElement.props;
|
||||
|
@ -26,12 +42,15 @@ export default function createDevTools(children) {
|
|||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
if (ReactReduxContext) {
|
||||
if (this.props.store && !this.props.store.liftedStore) {
|
||||
logError('NoLiftedStore');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!props.store && !context.store) {
|
||||
console.error(
|
||||
'Redux DevTools could not render. You must pass the Redux store ' +
|
||||
'to <DevTools> either as a "store" prop or by wrapping it in a ' +
|
||||
'<Provider store={store}>.'
|
||||
);
|
||||
logError('NoStore');
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -42,22 +61,50 @@ export default function createDevTools(children) {
|
|||
}
|
||||
|
||||
if (!this.liftedStore) {
|
||||
console.error(
|
||||
'Redux DevTools could not render. Did you forget to include ' +
|
||||
'DevTools.instrument() in your store enhancer chain before ' +
|
||||
'using createStore()?'
|
||||
);
|
||||
logError('NoLiftedStore');
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if (ReactReduxContext) {
|
||||
// For react-redux@6
|
||||
if (this.props.store) {
|
||||
if (!this.props.store.liftedStore) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Provider store={this.props.store.liftedStore}>
|
||||
<ConnectedMonitor {...monitorProps} />
|
||||
</Provider>
|
||||
);
|
||||
}
|
||||
return(
|
||||
<ReactReduxContext.Consumer>
|
||||
{props => {
|
||||
if (!props || !props.store) {
|
||||
logError('NoStore');
|
||||
return null;
|
||||
}
|
||||
if (!props.store.liftedStore) {
|
||||
logError('NoLiftedStore');
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Provider store={props.store.liftedStore}>
|
||||
<ConnectedMonitor {...monitorProps} />
|
||||
</Provider>
|
||||
);
|
||||
}}
|
||||
</ReactReduxContext.Consumer>
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.liftedStore) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ConnectedMonitor {...monitorProps}
|
||||
store={this.liftedStore} />
|
||||
<ConnectedMonitor {...monitorProps} store={this.liftedStore} />
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user