Small improvements:

- Switch to CodeMirror
- Switch to Parcel Bundler
- Fix synchronisation bug
- Update dependencies
This commit is contained in:
Fabian Stamm
2020-11-24 21:59:32 +01:00
parent e873ae0396
commit 86ae6acc92
32 changed files with 5232 additions and 6877 deletions

23
src/hooks.ts Normal file
View File

@ -0,0 +1,23 @@
import { useEffect, useMemo, useState } from "preact/hooks";
export function usePromise<T>(promiseFnc: () => Promise<T>, params: any[]) {
const promise = useMemo(promiseFnc, params);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(undefined);
const [value, setValue] = useState(undefined);
useEffect(() => {
let canceled = false;
promise
.then((res) => setValue(res))
.catch((err) => setError(err))
.finally(() => setLoading(false));
return () => {
canceled = true;
};
}, [promise]);
return [loading, error, value];
}