Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000| import React from 'react'; | |
| export default function useListener<T>(eventType: string): T | null { | |
| const [eventData, setEventData] = React.useState<T | null>(null); | |
| React.useEffect(() => { | |
| const handleEvent = (event: Event) => { | |
| if (event.type === eventType) { | |
| setEventData((event as CustomEvent<T>).detail) | |
| } |
| type EmitFunction<T> = (eventType: string, detail: T) => void; | |
| const useEmit = <T,>(): EmitFunction<T> => { | |
| const emit: EmitFunction<T> = (eventType: string, detail: T) => { | |
| const customEvent = new CustomEvent(eventType, { | |
| detail | |
| }) | |
| window.dispatchEvent(customEvent) | |
| } |
| import React, { ReactNode } from 'react'; | |
| interface ConditionProps { | |
| when: boolean; | |
| children: ReactNode; | |
| else?: ReactNode; | |
| } | |
| export function Condition({ when, children, else: elseContent }: ConditionProps) { | |
| if (when) { |
| import React, { ReactNode } from 'react'; | |
| interface ForProps<T> { | |
| each: T[]; | |
| render: (item: T, index: number) => ReactNode; | |
| } | |
| export function For<T>({ each, render }: ForProps<T>) { | |
| return <>{each.map((item, index) => render(item, index))}</>; | |
| } |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000