Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Created May 17, 2020 05:10
Show Gist options
  • Save zzdjk6/7deba1a9ff9e665f89aa36043f891b52 to your computer and use it in GitHub Desktop.
Save zzdjk6/7deba1a9ff9e665f89aa36043f891b52 to your computer and use it in GitHub Desktop.
Data Guard #EarlyReturn
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