Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't wrap arrow functions #158

Open
koszta opened this issue Jun 9, 2020 · 3 comments
Open

Can't wrap arrow functions #158

koszta opened this issue Jun 9, 2020 · 3 comments

Comments

@koszta
Copy link

koszta commented Jun 9, 2020

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
Copy link
Owner

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
Copy link

bobbyrinaldy commented Apr 19, 2022

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
Copy link

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants