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' | |
| import { observer } from 'mobx-react-lite' | |
| const MyComponent: React.FC = () => { | |
| // I would typically get this from context API with custom hook instead of local useMemo | |
| // e.g. const { name, age, loadAge, loadName } = useSomeService() | |
| const { age, name, loadAge, loadName } = React.useMemo(() => new SomeService(), []) | |
| React.useEffect(() => { | |
| loadAge() |
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
| # Configuration -> General Settings -> Startup Command | |
| pm2 serve /home/site/wwwroot/ --no-daemon --spa |
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' | |
| /** | |
| * Create a React Context that requires a value be provided explicitly (aka. no | |
| * default value). Returns the Context Provider + a useContext hook that | |
| * encapsulates access to the Context. | |
| */ | |
| export function createNamedContext<TValue>(name: string) { | |
| const Context = React.createContext<TValue | null>(null) |
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
| parameters: { | |
| controls: { | |
| disable: true, | |
| }, | |
| options: { showPanel: false }, | |
| } |
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 your snippets for typescript here. Each snippet is defined under a snippet name and has a prefix, body and | |
| // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
| // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
| // same ids are connected. | |
| // Example: | |
| // "Print to console": { | |
| // "prefix": "log", | |
| // "body": [ | |
| // "console.log('$1');", |
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' | |
| /** | |
| * Custom hook to set single properties on state objects. | |
| * | |
| * e.g. | |
| * const [state, setState] = useState({ name: 'John Doe' }) | |
| * const setProp = useSetProp(setState) | |
| * | |
| * const setName = setProp('name') |
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
| "resolutions": { | |
| "**/@typescript-eslint/eslint-plugin": "^4.2.0", | |
| "**/@typescript-eslint/parser": "^4.2.0", | |
| "**/eslint-plugin-react-hooks": "^4.1.2" | |
| } |
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' | |
| import { isError, useDependentState } from '../util' | |
| import Bulma from '../bulma' | |
| export type ValidatedValue< | |
| TValue, | |
| TRequired extends boolean | |
| > = TRequired extends true ? TValue : TValue | null | |
| export interface ValidatedInputProps<TValue, TRequired extends boolean> { |
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
| type Tagged<T extends string> = { | |
| type: T | |
| } | |
| export function switchExp< | |
| T extends Tagged<string>, | |
| M extends { [P in T['type']]: T extends Tagged<P> ? (t: T) => any : never } | |
| >(value: T, map: M): ReturnType<M[keyof M]> { | |
| return map[value.type as keyof M](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 interface Spec<K extends string, T> { | |
| ctr: (raw: string) => T, | |
| key: K, | |
| match: RegExp | |
| } | |
| type Data<T, D> = { | |
| type: T | |
| } & { [P in keyof D]: D[P] }; |