chore: use purecomponent replace shallow compare (#21575)

This commit is contained in:
zefeng 2020-02-25 16:23:34 +08:00 committed by GitHub
parent 2f91dd4925
commit 55133b7757
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 12 deletions

View File

@ -1,7 +1,6 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import classNames from 'classnames';
import shallowEqual from 'shallowequal';
import omit from 'omit.js';
import Checkbox, { CheckboxChangeEvent } from './Checkbox';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
@ -48,7 +47,7 @@ export const GroupContext = React.createContext<{ checkboxGroup: any }>({
checkboxGroup: undefined,
});
class CheckboxGroup extends React.Component<CheckboxGroupProps, CheckboxGroupState> {
class CheckboxGroup extends React.PureComponent<CheckboxGroupProps, CheckboxGroupState> {
static defaultProps = {
options: [],
};
@ -77,10 +76,6 @@ class CheckboxGroup extends React.Component<CheckboxGroupProps, CheckboxGroupSta
};
}
shouldComponentUpdate(nextProps: CheckboxGroupProps, nextState: CheckboxGroupState) {
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
}
getOptions() {
const { options } = this.props;
// https://github.com/Microsoft/TypeScript/issues/7960

View File

@ -1,7 +1,6 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import classNames from 'classnames';
import shallowEqual from 'shallowequal';
import Radio from './radio';
import {
RadioGroupProps,
@ -24,7 +23,7 @@ function getCheckedValue(children: React.ReactNode) {
return matched ? { value } : undefined;
}
class RadioGroup extends React.Component<RadioGroupProps, RadioGroupState> {
class RadioGroup extends React.PureComponent<RadioGroupProps, RadioGroupState> {
static defaultProps = {
buttonStyle: 'outline' as RadioGroupButtonStyle,
};
@ -76,10 +75,6 @@ class RadioGroup extends React.Component<RadioGroupProps, RadioGroupState> {
};
}
shouldComponentUpdate(nextProps: RadioGroupProps, nextState: RadioGroupState) {
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
}
onRadioChange = (ev: RadioChangeEvent) => {
const lastValue = this.state.value;
const { value } = ev.target;