我有这个代码:
const ChatsPage = () => {
let username = ""
let secret = ""
useEffect(() => {
axios
.post('http://localhost:3001/authenticate')
.then((response) => {
username = response.data.username
secret = response.data.secret
})
.catch((error) => {
console.log(error);
});
}, []);
let chatProps = useMultiChatLogic('xxxxx-xxx-xxx-xxx-xxx', username, secret);
return (
);
}
问题在于 let chatProps = useMultiChatLogic('xxxx-xx-x-xx-xxx', username, Secret); 在 useEffect 完成之前运行。我尝试将其移至 .then 内部,但它给出了钩子错误和其他一些东西,但没有任何效果。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号