Merge pull request #3594 from paulkaplan/too-many-renders

Fix a couple areas where we are rendering too much
This commit is contained in:
Paul Kaplan authored and GitHub committed 2018-11-01 11:33:16 -04:00
commit a119c96df5
2 files changed
+16 -12

No files matched your search

+6 -5
View File
@@ -17,7 +17,7 @@ class LanguageSelector extends React.Component {
}
handleChange (e) {
const newLocale = e.target.value;
if (this.props.supportedLocales.includes(newLocale)) {
if (this.props.messagesByLocale[newLocale]) {
this.props.onChangeLanguage(newLocale);
document.documentElement.lang = newLocale;
}
@@ -25,7 +25,7 @@ class LanguageSelector extends React.Component {
render () {
const {
onChangeLanguage, // eslint-disable-line no-unused-vars
supportedLocales, // eslint-disable-line no-unused-vars
messagesByLocale, // eslint-disable-line no-unused-vars
children,
...props
} = this.props;
@@ -43,13 +43,14 @@ class LanguageSelector extends React.Component {
LanguageSelector.propTypes = {
children: PropTypes.node,
currentLocale: PropTypes.string.isRequired,
onChangeLanguage: PropTypes.func.isRequired,
supportedLocales: PropTypes.arrayOf(PropTypes.string)
// Only checking key presence for messagesByLocale, no need to be more specific than object
messagesByLocale: PropTypes.object, // eslint-disable-line react/forbid-prop-types
onChangeLanguage: PropTypes.func.isRequired
};
const mapStateToProps = state => ({
currentLocale: state.locales.locale,
supportedLocales: Object.keys(state.locales.messagesByLocale)
messagesByLocale: state.locales.messagesByLocale
});
const mapDispatchToProps = dispatch => ({
+10 -7
View File
@@ -55,13 +55,15 @@ class SpriteSelectorItem extends React.Component {
window.removeEventListener('mousemove', this.handleMouseMove);
window.removeEventListener('touchend', this.handleMouseUp);
window.removeEventListener('touchmove', this.handleMouseMove);
this.props.onDrag({
img: null,
currentOffset: null,
dragging: false,
dragType: null,
index: null
});
if (this.props.dragging) {
this.props.onDrag({
img: null,
currentOffset: null,
dragging: false,
dragType: null,
index: null
});
}
setTimeout(() => {
this.noClick = false;
});
@@ -156,6 +158,7 @@ SpriteSelectorItem.propTypes = {
body: PropTypes.string
}),
dragType: PropTypes.string,
dragging: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
index: PropTypes.number,
name: PropTypes.string,