1

在最近的一天,我一直在尝试将 react-i18next 添加到 nextJs 项目到 i18n,为此我在他们的仓库中使用了 nextJs 示例,并尝试通过将我的代码逐步添加到他们的代码中来遵循它,一切正常,直到我添加了我的 index.js ,这是它的代码

`

class Homepage extends Component {
constructor(props) {
  super(props);
}

static getInitialProps({ req, store }) {
  const token = req && req.cookies && req.cookies.token;
  if (token && store) store.dispatch(authUser(token));
}

componentDidMount() {
  if (this.props.isAuthenticated) this.props.getUrlsList();
}

shouldComponentUpdate(nextProps) {
  return this.props.isAuthenticated !== nextProps.isAuthenticated;
}

render() {
const { appUser } = this.props;
const { isAuthenticated } = this.props;
const needToLogin = !isAuthenticated && <NeedToLogin />;
const table = isAuthenticated && <Table />;
const {  t } = this.props;

return (
  <BodyWrapper>
    <Shortener />
    {needToLogin}
    {table}
    <Features />
    <NewsLetter />
    <Footer />
    <Intercom appID="a8a3gqf7" />
  </BodyWrapper>
);
}
}

Homepage.propTypes = {
isAuthenticated: PropTypes.bool.isRequired,
getUrlsList: PropTypes.func.isRequired,
};

const mapStateToProps = ({ auth: { isAuthenticated } }) => ({                 isAuthenticated });

const mapDispatchToProps = dispatch => ({
   getUrlsList: bindActionCreators(getUrlsList, dispatch),
});

Homepage = withI18next(['home', 'common'])(Homepage);
export default withRedux(initialState , mapStateToProps, mapDispatchToProps)(Homepage);

`

它给了我这个错误

Error: No page context

4

0 回答 0