-2

invalid hook call. hooks can only be called inside of the body of a function component

This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See for tips about how to debug and fix this problem.

import './Login.css'
import { Button } from '@material-ui/core';
import { login } from '../features/userSlice';
import { auth, provider } from './firebase';
import { useDispatch } from 'react-redux';

function Login() {
    const dispath = useDispatch;

    const signIn = () => {
        auth.signInWithPopup(provider)
        .then(({user}) => {
            dispath(login({
                displayName: user.displayName,
                email: user.email,
                photoUrl: user.PhotoURL,
            }));
        })
        .catch((error) => alert(error.message));
    };

    return (
        <div className="login">
            <div className="login_container">
                <img src="https://i.pinimg.com/originals/39/21/6d/39216d73519bca962bd4a01f3e8f4a4b.png" alt=""/>
                <p>Sign in with google</p>
                <Button variant="contained" color="primary" onClick={signIn}>Login </Button>
            </div>
        </div>
    )
}

export default Login
Sinan Yaman
  • 5,714
  • 2
  • 15
  • 35
  • Does this answer your question? [Invalid hook call. Hooks can only be called inside of the body of a function component](https://stackoverflow.com/questions/56663785/invalid-hook-call-hooks-can-only-be-called-inside-of-the-body-of-a-function-com) – champion-runner Mar 21 '21 at 10:38

1 Answers1

1

I suspect this is where the problem is: Change this from

 const dispath = useDispatch;

To

 const dispath = useDispatch();

Good Luck, let me know if it works

crispengari
  • 7,901
  • 7
  • 45
  • 53