Reputation: 33
I get an error in the console as
error!! [Error: 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:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- You might have more than one copy of React in the same app*
import firebase from '../../database/firebase';
import { useDispatch } from 'react-redux';
import * as actions from "../../store/actions";
export const userProfilePcture =(id)=>{
const image = firebase.storage().ref(id + '/profilePicture');
var user = firebase.auth().currentUser;
image.getDownloadURL().then((url) => {
user.updateProfile({
photoURL: url
}).then(() =>{
console.log("updete succefully");
updeteUser();
}).catch(error =>{
console.log("error!!",error);
});
});
};
export const updeteUser=()=>{
const dispatch=useDispatch();
var user = firebase.auth().currentUser;
dispatch(actions.updateUser(user));
}
How can I avoid this?
Upvotes: 1
Views: 626
Reputation: 1651
This is the hook you are using:
const dispatch=useDispatch();
You can only use hooks inside a React functional component. Right now you are trying to use this hook in a normal javascript function.
Upvotes: 1