Last active
August 7, 2020 09:21
-
-
Save kt3k/0013ff70e0a0c05a8b18e5f302e42868 to your computer and use it in GitHub Desktop.
doIf
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
import { useEffect } from 'react' | |
export const doIf = (cond: boolean, effect: () => unknown): void => { | |
useEffect(() => { | |
if (cond) { | |
effect() | |
} | |
}, [cond]) | |
} |
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
import React from 'react' | |
export const SomeComponent: React.FC = () => { | |
const { isLoggedIn } = useAuthState() | |
doIf(isLoggedIn, () => { | |
setClient(client(...withAuthInfo...)) | |
}) | |
return ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment