我无法使用出色的react-i18next
更新我的React应用。
我有一个“抽象”到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;
}