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
let _detectedFlexGapSupported = false; | |
let _isFlexGapSupported = false; | |
export const checkFlexGapSupported = (): boolean => { | |
if (_detectedFlexGapSupported) { | |
return _isFlexGapSupported; | |
} | |
// create flex container with row-gap set | |
const flex = document.createElement("div"); |
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
const MyComponent: React.FC = () => { | |
return ( | |
<Data1Guard> | |
{(data1) => ( | |
<Data2Guard data1={data1}> | |
{(data2) => ( | |
<AggregateDataGuard data1={data1} data2={data2}> | |
{(result) => <ResultDisplay result={result} />} | |
</AggregateDataGuard> | |
)} |
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); |
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
const MyComponent: React.FC = () => { | |
const data1 = useData1(); | |
const data2 = useData2(data1); | |
const result = React.useMemo(() => { | |
if (!data1 || !data2) { | |
return null; | |
} | |
return aggregateData(data1, data2); | |
}, [data1, data2]); |
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
const MyComponent: React.FC = () => { | |
const data1 = useData1(); | |
if (!data1) { | |
return null; | |
} | |
const data2 = useData2(data1); | |
if (!data2) { | |
return null; | |
} |
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
const MyComponent: React.FC = () => { | |
const { loading, error, data } = useData(); | |
if (loading) { | |
return <Spinner />; | |
} | |
if (error) { | |
return <Alert>{error.message}</Alert>; | |
} |
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 Props = { | |
loading: boolean; | |
error?: Error; | |
data: Data; | |
}; | |
const MyComponent: React.FC<Props> = (props) => { | |
if (props.loading) { | |
return <Spinner />; | |
} |
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
function doSomething(user, data) { | |
if (!hasPermission(user)) { | |
throw new PermissionDeniedError(); | |
} | |
if (!isNetworkAvailable()) { | |
saveInQueue(user, data); | |
return; | |
} |
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
function doSomething(user, data) { | |
if (hasPermission(user)) { | |
if (isNetworkAvailable()) { | |
if (isValid(data)) { | |
sendToServer(user, data); | |
} else { | |
throw new DataInvalidError(); | |
} | |
} else { | |
saveInQueue(user, data); |
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
// Use a polyfill to make it useable in old browswers | |
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'; | |
// When abort happens, this error will be throw | |
export class AbortError extends Error { | |
constructor(message: string = 'Aborted') { | |
super(message); | |
this.name = 'AbortError'; | |
} | |
} |
NewerOlder