Created
January 30, 2022 14:02
-
-
Save ahmadabdul3/b1838124ccbdd6c1d658293d99470578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useLogin(/* any context you want to pass in here */) { | |
const [data, setData] = useState(''); | |
const [error, setError] = useState(''); | |
const [loading, setLoading] = useState(''); | |
useEffect(() => { | |
async function login() { | |
try { | |
const val = await login(); | |
setData(val); | |
} catch (e) { | |
setError(e); | |
} finally { | |
setLoading(false); | |
} | |
} | |
}); | |
return { data, error, loading }; | |
} | |
function Component() { | |
const { data: loginData, error: loginError, loading: loginLoading } = useLogin(); | |
// etc... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment