Buckets:
| import { createContext, Show, useContext, type ParentProps } from "solid-js" | |
| export function createSimpleContext<T, Props extends Record<string, any>>(input: { | |
| name: string | |
| init: ((input: Props) => T) | (() => T) | |
| }) { | |
| const ctx = createContext<T>() | |
| return { | |
| context: ctx, | |
| provider: (props: ParentProps<Props>) => { | |
| const init = input.init(props) | |
| return ( | |
| // @ts-expect-error | |
| <Show when={init.ready === undefined || init.ready === true}> | |
| <ctx.Provider value={init}>{props.children}</ctx.Provider> | |
| </Show> | |
| ) | |
| }, | |
| use() { | |
| const value = useContext(ctx) | |
| if (!value) throw new Error(`${input.name} context must be used within a context provider`) | |
| return value | |
| }, | |
| } | |
| } | |
Xet Storage Details
- Size:
- 761 Bytes
- Xet hash:
- eac94d68f7a176194b768974541b1a8636fcec6c26c1088a87706e6836006168
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.