Added .off(...)

This commit is contained in:
Federico Kereki
2018-07-12 20:16:29 -03:00
parent 6321d9ad04
commit 885972f608
2 changed files with 14 additions and 4 deletions
+3 -1
View File
@@ -34,4 +34,6 @@ i18n.use(LanguageDetector).init({
} }
}); });
export default i18n; const t = i18n.t.bind(i18n); // to allow using t(...) instead of i18n.t(...)
export { i18n, t };
+11 -3
View File
@@ -3,8 +3,7 @@
import React from "react"; import React from "react";
import "./styles.css"; import "./styles.css";
import i18n from "./i18n"; import { i18n, t } from "./i18n";
const t = i18n.t.bind(i18n);
export class I18nForm extends React.PureComponent< export class I18nForm extends React.PureComponent<
{}, {},
@@ -20,8 +19,17 @@ export class I18nForm extends React.PureComponent<
thingColor: "NC" thingColor: "NC"
}; };
constructor(props) {
super(props);
this.rerender = () => this.forceUpdate();
}
componentDidMount() { componentDidMount() {
i18n.on("languageChanged", () => this.forceUpdate()); i18n.on("languageChanged", this.rerender);
}
componentWillUnmount() {
i18n.off("languageChanged", this.rerender);
} }
render() { render() {