Skip to content

Commit

Permalink
Add usePureComponent option
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Hoseinian committed Dec 5, 2017
1 parent 4276370 commit 39e9468
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ let defaultOptions = {
bindI18n: 'languageChanged loaded',
bindStore: 'added removed',
translateFuncName: 't',
nsMode: 'default'
nsMode: 'default',
usePureComponent: false,
};

let i18n;
Expand Down
10 changes: 10 additions & 0 deletions src/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import hoistStatics from 'hoist-non-react-statics';
import { getDefaults, setDefaults, getI18n, setI18n } from './context';
import I18n from './I18n';
import shallowEqual from 'fbjs/lib/shallowEqual';

function getDisplayName(component) {
return component.displayName || component.name || 'Component';
Expand All @@ -25,6 +26,15 @@ export default function translate(namespaces, options = {}) {

this.getWrappedInstance = this.getWrappedInstance.bind(this);
}


shouldComponentUpdate(nextProps){
if(!this.options.usePureComponent){
return true
}

return !shallowEqual(this.props, nextProps);
}

getWrappedInstance() {
if (!this.options.withRef) {
Expand Down

0 comments on commit 39e9468

Please sign in to comment.