Skip to content

HOC not calling getInitialProps #6115

@theprobugmaker

Description

@theprobugmaker

I'm trying to create a HOC for withCurrentUser like this:

import React, { Component } from 'react';

export default WrappedComponent =>
  // eslint-disable-next-line react/prefer-stateless-function
  class extends Component {
    static getInitialProps({ apollo }) {
      console.log('it called me');
      console.log(apollo);

      return { hello: "world" };
    }

    render() {
      return (
        <>
          <h1>hello from withCurrentUser</h1>
          <WrappedComponent {...this.props} />
        </>
      );
    }
  };

and then trying to use like this:

import React from 'react';

import withCurrentUser from '../../hocs/withCurrentUser';

const NavBar = ({ hello }) => <h1>NavBar {hello}</h1>;

export default withCurrentUser(NavBar);

But it's not calling getInitialProps. What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions