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
// The implementation below is inspired by the [example](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#examples) | |
// that shows how a fetch operation can be aborted using the signal option. | |
// See https://gist.github.com/tjunghans/da50cc29f3f965d587db99c2f44813f1 for an example on how `doSomethingAsync` is used. | |
function doSomethingAsync( | |
// payload can be anything. It's just an example | |
payload, | |
{ signal }: { signal?: AbortSignal } = {} | |
): Promise<any> { | |
// Abort immediately if `abort` was already called. |
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
// See https://gist.github.com/tjunghans/0129439ad12b37b98c72477156cddbce for the definition of `doSomethingAsync`. | |
function MyComponent({ someprop }) { | |
const [value, setValue] = React.useState(""); | |
React.useEffect(() => { | |
// Create an instance of the AbortController that will | |
// be used to abort in the useEffect return. | |
const controller = new AbortController(); | |
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, { type DetailedHTMLProps, type HTMLAttributes } from "react"; | |
export const createComponentMock = < | |
T extends DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> | |
>( | |
componentName: string | |
) => { | |
const fakeComponent = (props: T) => ( | |
<div data-testid={componentName} {...props} /> | |
); |
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
// Place this file inside <projectRoot>/__mocks__/react-query.js | |
export const useQuery = jest | |
.fn() | |
.mockReturnValue({ data: {}, isLoading: false, error: {} }); | |
export class QueryClient {} |
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
On xyz master branch run the following to get the count for the year 2024. | |
git log --format="%h %an %Cgreen%as%Creset %d" --first-parent --tags --no-walk | grep -c -e '2024' | |
Omit “-c” to list the entries for 2024: | |
git log --format="%h %an %Cgreen%as%Creset %d" --first-parent --tags --no-walk | grep -e '2024' |
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
const isPortnumber = (value: number): boolean => { | |
// https://en.wikipedia.org/wiki/Registered_port | |
return value >= 0 && value <= 65535; | |
}; | |
const isValidPortnumber = (value: unknown): value is number => { | |
if (typeof value === "number") { | |
return isPortnumber(value); | |
} |
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
export enum ActionType { | |
CreateSomething, | |
UpdateSomething, | |
DeleteSomething, | |
RetrieveSomething | |
} |
OlderNewer