Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce number of StrictMode warnings #6287

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unsafe lifecycles
jeffchheng committed Aug 6, 2018
commit 97f4fad16c2d9e610dd4cf183cc957946903c388
2 changes: 1 addition & 1 deletion packages/react-router-dom/modules/BrowserRouter.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ class BrowserRouter extends React.Component {

history = createHistory(this.props);

componentWillMount() {
componentDidMount() {
warning(
!this.props.history,
"<BrowserRouter> ignores the history prop. To use a custom history, " +
2 changes: 1 addition & 1 deletion packages/react-router-dom/modules/HashRouter.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class HashRouter extends React.Component {

history = createHistory(this.props);

componentWillMount() {
componentDidMount() {
warning(
!this.props.history,
"<HashRouter> ignores the history prop. To use a custom history, " +
2 changes: 1 addition & 1 deletion packages/react-router/modules/MemoryRouter.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ class MemoryRouter extends React.Component {

history = createHistory(this.props);

componentWillMount() {
componentDidMount() {
warning(
!this.props.history,
"<MemoryRouter> ignores the history prop. To use a custom history, " +
10 changes: 5 additions & 5 deletions packages/react-router/modules/Prompt.js
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ class Prompt extends React.Component {
}
}

componentWillMount() {
componentDidMount() {
invariant(
this.context.router,
"You should not use <Prompt> outside a <Router>"
@@ -46,10 +46,10 @@ class Prompt extends React.Component {
if (this.props.when) this.enable(this.props.message);
}

componentWillReceiveProps(nextProps) {
if (nextProps.when) {
if (!this.props.when || this.props.message !== nextProps.message)
this.enable(nextProps.message);
componentDidUpdate(prevProps) {
if (this.props.when) {
if (!prevProps.when || prevProps.message !== this.props.message)
this.enable(this.props.message);
} else {
this.disable();
}
4 changes: 2 additions & 2 deletions packages/react-router/modules/Router.js
Original file line number Diff line number Diff line change
@@ -64,9 +64,9 @@ class Router extends React.Component {
});
}

componentWillReceiveProps(nextProps) {
componentDidUpdate(prevProps) {
warning(
this.props.history === nextProps.history,
prevProps.history === this.props.history,
"You cannot change <Router history>"
);
}
2 changes: 1 addition & 1 deletion packages/react-router/modules/StaticRouter.js
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ class StaticRouter extends React.Component {

handleBlock = () => noop;

componentWillMount() {
componentDidMount() {
warning(
!this.props.history,
"<StaticRouter> ignores the history prop. To use a custom history, " +
6 changes: 3 additions & 3 deletions packages/react-router/modules/Switch.js
Original file line number Diff line number Diff line change
@@ -26,14 +26,14 @@ class Switch extends React.Component {
);
}

componentWillReceiveProps(nextProps) {
componentDidUpdate(prevProps) {
warning(
!(nextProps.location && !this.props.location),
!(this.props.location && !prevProps.location),
'<Switch> elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.'
);

warning(
!(!nextProps.location && this.props.location),
!(!this.props.location && prevProps.location),
'<Switch> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.'
);
}