[英]Invalid hook call. React.js
Import useState from react, paste it to body function, but react tells me Wrong use hooks.从 react 导入 useState,将其粘贴到 body 函数中,但是 react 告诉我错误使用钩子。 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.您返回的 getUserId 不是 jsx。 If your function is intended to be a react functionnal component then it is supposed to return a jsx.
如果您的函数旨在成为反应功能组件,那么它应该返回一个 jsx。 If not then you cannot use a react hook like useState.
如果没有,那么你不能使用像 useState 这样的反应钩子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.