Search code examples
javascriptreactjstypescriptcreate-react-apphigher-order-components

React HOC component in typescript gives warnings (converting from non-typescript)


I'm having the following simple HOC component in react + typescript.

export const withFirebase = <P extends object>(
  Component: React.ComponentType<P>
) =>
  class WithFirebase extends React.Component<P> {
    render() {
      return (
        <FirebaseContext.Consumer>
          {firebase => <Component {...this.props} firebase={firebase} />}
        </FirebaseContext.Consumer>
      )
    }
  }

export default FirebaseContext

I'm converting this component from non-type script to a typescript function but ESlint gives me the following errors: Missing return type on function. What am I missing here? Should I write my HOC component differently?


Solution

  • Tried to provide return type on function?

    export const withFirebase = <P extends object>(
      Component: React.ComponentType<P>
    ): React.ComponentType<P> =>