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

Ref.current returns null when trying to invoke handleLogin() #90

Open
yarvindeashwar opened this issue Jun 13, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@yarvindeashwar
Copy link

Hello,

I'm currently experiencing an issue with the react-linkin-login-oauth2 library. I'm attempting to use a ref to the LinkedIn component in order to programmatically invoke the handleLogin function. However, I'm finding that ref.current is returning null, resulting in an error.

// truncated for brevity...
const linkedInRef = React.createRef();

// In the render method:
<LinkedIn
ref={linkedInRef}
clientId="86pfpmycxuyu49"
onFailure={handleFailure}
onSuccess={handleSuccess}
redirectUri="http://localhost:3000/linkedin"
className="d-none"

{() => {}}

// And later, when trying to invoke handleLogin:
console.log("linkedInRef.current:", linkedInRef.current);
if (isSwitchOn) {
linkedInRef.current?.handleLogin();
}

When handleLogin is invoked, I receive an error stating linkedInRef.current: null.

The LinkedIn component is not conditionally rendered, so I would expect the ref to be properly initialized. I'm using the latest versions of both React and the react-linkedin-login-oauth2 library.

Am I missing something, or is this a potential issue with the library?

Thanks in advance for your help.

@yarvindeashwar yarvindeashwar added the bug Something isn't working label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant