Answer the question
In order to leave comments, you need to log in
How to push in state redux?
How to push a custom hook into state redux that checks if the user is authorized or not?
import {useEffect, useState} from 'react'
import {localURL} from "../const";
export const useAuth = () => {
const [user, setUser] = useState({})
useEffect(() => {
fetch(`${localURL}/auth/login`)
.then((res) => res.json())
.then((res) => {
setUser(res.user)
})
.then((res) => console.log(user))
.catch((e) => console.log(e));
}, [])
return user
}
const initialState = {
user: {}
}
export default function rootReducer(state = initialState, action) {
return state
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question