我在更新我的 React 应用程序时遇到了问题react-i18next
。
我有一个“抽象”与 Redux 的连接的 HOC。这个 HOC 看起来像这样:
// This is the component I used to use, but it doesn't exist anymore in v10:
import { I18n } from "react-i18next";
export const myHOC = identifier => ({
actions,
translations,
}) => WrappedComponent => {
// connnect the WrappedComponent to Redux:
const ConnectedComponent = connect(
// generate the mapStateToProps automatically
mapStateToProps(),
actions
)
class MyConnnector extends Component {
// constructor:
constructor(props, context) {
super(props);
// Can't say why new React new Context API doesn't bring
// store (from Redux) and i18n (from react-i18next) are undefined here:
console.log(context.store, context.i18n); // undefined, undefined
}
// then render method:
render() {
// If there are translation to use...
if (translations) {
return (
// Return the I18n component with the previously ConnectedComponent as a child:
// HERE! This component doesn't exists anymore. What's the best way to replace it?
<I18n i18n={this.context.i18n} ns={[key, "commom"]}>
<ConnnectedComponent {...this.props} />
</I18n>
);
}
return <ConnectedComponent {...this.props} />
}
}
return MyConnnector;
}