deepakaggarwal7 / react-social-login

MIT License
373 stars 143 forks source link

Can't wrap arrow functions #158

Open koszta opened 4 years ago

koszta commented 4 years ago

It gives

TypeError: Cannot read property 'render' of undefined

The problem is that arrow functions don't have a prototype and therefore the stateless component test throws TypeError.

see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

https://github.com/deepakaggarwal7/react-social-login/blob/master/src/index.js#L48

deepakaggarwal7 commented 3 years ago

Could you please share sample code? I agree that prototype isn't available for arrow functions, but I created one which worked. If you share your breaking usage, I might be able to fix it sooner.

bobbyrinaldy commented 2 years ago

same for me on nextjs, here's the following component that i created

import { FC, ReactNode } from 'react';
import SocialLogin from 'react-social-login';

type ISocialButtonProps = {
  children: ReactNode;
  props: any;
  triggerLogin: any;
};

const SocialButton: FC = (props: ISocialButtonProps) => {
  const { triggerLogin, children, ...otherProps } = props;
  return (
    <button onClick={triggerLogin} {...otherProps}>
      {children}
    </button>
  );
};

export default SocialLogin(SocialButton);

code above throw me an error :

TypeError: Cannot read property 'render' of undefined

which coming from this line of code:

// node_modules/react-social-login/dist/social-login.js line 979
_this.isStateless = !WrappedComponent.prototype.render;
bobbyrinaldy commented 2 years ago

i did converting my Arrow function to a Class component, and its working. i think yes its because arrow function did not have any prototype, maybe you should adding another condition when people using an arrow function instead of class component

here's the code , maybe someone in future needed it.

import React, { Component, ReactNode } from 'react';
import SocialLogin from 'react-social-login';

type ISocialButtonProps = {
  children: ReactNode;
  props: any;
  triggerLogin: any;
};

export class SocialButton extends Component<ISocialButtonProps> {
  render() {
    return (
      <button onClick={this.props.triggerLogin} {...this.props}>
        {this.props.children}
      </button>
    );
  }
}

export default SocialLogin(SocialButton);