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

perf: Use PureComponent to avoid useless re-renders (fixes #7248) #7258

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Changes from all commits
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
perf: Use PureComponent to avoid useless re-renders
theboolean committed Apr 14, 2020

Verified

This commit was signed with the committer’s verified signature.
theboolean Lorenzo Cesana
commit 8bad2fb63a178f00866155297d6cdbe77bb386f2
2 changes: 1 addition & 1 deletion packages/react-router-dom/modules/BrowserRouter.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import warning from "tiny-warning";
/**
* The public API for a <Router> that uses HTML5 history.
*/
class BrowserRouter extends React.Component {
class BrowserRouter extends React.PureComponent {
history = createHistory(this.props);

render() {
2 changes: 1 addition & 1 deletion packages/react-router-dom/modules/HashRouter.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import warning from "tiny-warning";
/**
* The public API for a <Router> that uses window.location.hash.
*/
class HashRouter extends React.Component {
class HashRouter extends React.PureComponent {
history = createHistory(this.props);

render() {
2 changes: 1 addition & 1 deletion packages/react-router-native/BackButton.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { BackHandler } from "react-native";

import { __RouterContext as RouterContext } from "react-router";

class BackButton extends React.Component {
class BackButton extends React.PureComponent {
handleBack = () => {
if (this.history.index === 0) {
return false; // home screen
2 changes: 1 addition & 1 deletion packages/react-router-native/DeepLinking.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { __RouterContext as RouterContext } from "react-router";

const protocolAndSlashes = /.*?:\/\//g;

class DeepLinking extends React.Component {
class DeepLinking extends React.PureComponent {
push(url) {
const pathname = url.replace(protocolAndSlashes, "");
this.history.push(pathname);
2 changes: 1 addition & 1 deletion packages/react-router-native/Link.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import PropTypes from "prop-types";

import { __RouterContext as RouterContext } from "react-router";

export default class Link extends React.Component {
export default class Link extends React.PureComponent {
static defaultProps = {
component: TouchableHighlight,
replace: false
2 changes: 1 addition & 1 deletion packages/react-router-native/experimental/StackRoute.js
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ const PARENT_TRAVEL_DISTANCE = 100;
const PARENT_FINAL_OPACITY = 0.25;
const CARD_SHADOW_RADIUS = 10;

class AnimatedStack extends React.Component {
class AnimatedStack extends React.PureComponent {
static propTypes = {
title: PropTypes.any,
content: PropTypes.any,
4 changes: 2 additions & 2 deletions packages/react-router-native/experimental/TabRoutes.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { View } from "react-native";

import Link from "../Link.js";

export class TabRoutes extends React.Component {
export class TabRoutes extends React.PureComponent {
render() {
const { children } = this.props;
return (
@@ -36,7 +36,7 @@ export class TabRoutes extends React.Component {
}
}

export class TabRoute extends React.Component {
export class TabRoute extends React.PureComponent {
render() {
const { renderContent, path } = this.props;
return <Route path={path} render={renderContent} />;
2 changes: 1 addition & 1 deletion packages/react-router-native/index.android.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import {
Prompt
} from "react-router-native";

class ReactRouterNative extends React.Component {
class ReactRouterNative extends React.PureComponent {
render() {
return (
<NativeRouter>
2 changes: 1 addition & 1 deletion packages/react-router/modules/Lifecycle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

class Lifecycle extends React.Component {
class Lifecycle extends React.PureComponent {
componentDidMount() {
if (this.props.onMount) this.props.onMount.call(this, this);
}
2 changes: 1 addition & 1 deletion packages/react-router/modules/MemoryRouter.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import Router from "./Router.js";
/**
* The public API for a <Router> that stores location in memory.
*/
class MemoryRouter extends React.Component {
class MemoryRouter extends React.PureComponent {
history = createHistory(this.props);

render() {
2 changes: 1 addition & 1 deletion packages/react-router/modules/Route.js
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ function evalChildrenDev(children, props, path) {
/**
* The public API for matching a single path and rendering.
*/
class Route extends React.Component {
class Route extends React.PureComponent {
render() {
return (
<RouterContext.Consumer>
2 changes: 1 addition & 1 deletion packages/react-router/modules/Router.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import RouterContext from "./RouterContext.js";
/**
* The public API for putting history on context.
*/
class Router extends React.Component {
class Router extends React.PureComponent {
static computeRootMatch(pathname) {
return { path: "/", url: "/", params: {}, isExact: pathname === "/" };
}
2 changes: 1 addition & 1 deletion packages/react-router/modules/StaticRouter.js
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ function noop() {}
* location changes in a context object. Useful mainly in testing and
* server-rendering scenarios.
*/
class StaticRouter extends React.Component {
class StaticRouter extends React.PureComponent {
navigateTo(location, action) {
const { basename = "", context = {} } = this.props;
context.action = action;
2 changes: 1 addition & 1 deletion packages/react-router/modules/Switch.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import matchPath from "./matchPath.js";
/**
* The public API for rendering the first <Route> that matches.
*/
class Switch extends React.Component {
class Switch extends React.PureComponent {
render() {
return (
<RouterContext.Consumer>