#reactjs #graphql #next.js #apollo-client
Вопрос:
я новичок в react. у меня возникли проблемы с переключением страниц после завершенного заявления в react.
export default function Login(){
const [Iemail, setEmail] = useState("")
const [Ipassword, setPassword] = useState("")
const emailInput = event => setEmail(event.target.value)
const passInput = event => setPassword(event.target.value)
const router = useRouter()
const [loginUser, { error }] = useMutation(LOGIN_QUERY,
{
onCompleted: (data) => {
alert(JSON.stringify(data))
router.push("/login-reset")
},
onError: (error) => {
console.log(error); // the error if that is the case
}
})
const submitForm = async () => {
if(Iemail === "" || Ipassword === ""){
alert('Please input username / password!')
}else{
loginUser({
variables: {
username: Iemail,
password: Ipassword,
}
},
)
if (error) {
alert('error')
console.log(error);
}else{
alert("success!")
}
}
};
появится предупреждение об успешном выполнении, если появится, и также появится предупреждение о данных ответа
did i do the wrong code? and i want to know how to mutation with best practice in auth. thanks