Skip to content

Instantly share code, notes, and snippets.

@ahmadabdul3
Created January 30, 2022 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadabdul3/b1838124ccbdd6c1d658293d99470578 to your computer and use it in GitHub Desktop.
Save ahmadabdul3/b1838124ccbdd6c1d658293d99470578 to your computer and use it in GitHub Desktop.
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