Import useState from react, paste it to body function, but react tells me Wrong use hooks. Although another hook works like this.
import {getAuth} from 'firebase/auth';
import {useState} from 'react';
const useAuth = () => {
const [state, setState] = useState(null); //wrong use
const auth = getAuth();
const getUserId = () => {
return new Promise((resolve, reject) => {
auth.onAuthStateChanged((user) => {
if (user) {
resolve(user.uid);
} else {
resolve(null);
}
});
});
};
return {
getUserId,
};
};
export default useAuth;
Your returned getUserId is not a jsx. If your function is intended to be a react functionnal component then it is supposed to return a jsx. If not then you cannot use a react hook like useState.