Created
May 17, 2020 05:10
-
-
Save zzdjk6/7deba1a9ff9e665f89aa36043f891b52 to your computer and use it in GitHub Desktop.
Data Guard #EarlyReturn
This file contains 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
type Data1GuardProps = { | |
children: (data1: Data1) => JSX.Element; | |
}; | |
const Data1Guard: React.FC<Data1GuardProps> = ({ children }) => { | |
const data1 = useData1(); | |
if (!data1) { | |
return null; | |
} | |
return children(data1); | |
}; | |
type Data2GuardProps = { | |
data1: Data1; | |
children: (data2: Data2) => JSX.Element; | |
}; | |
const Data2Guard: React.FC<Data2GuardProps> = ({ data1, children }) => { | |
const data2 = useData2(data1); | |
if (!data2) { | |
return null; | |
} | |
return children(data2); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment