Skip to content

Instantly share code, notes, and snippets.

@henrikhermansen
henrikhermansen / clean-svelte.js
Created July 18, 2019 09:40
Run this postinstall to be able to compile Svelte using Parcel
const fs = require('fs').promises;
const svelteDir = 'node_modules/svelte';
const extname = path => path.split('.').pop();
const filename = path => {
const arr = path.split('.');
arr.pop();
return arr.join('.');
};
@henrikhermansen
henrikhermansen / useIsMountedRef.js
Created March 20, 2019 12:48
A hook to check if your component is mounted, before setting state after an async operation. It returns the ref, so you use it with `isMounted.current`.
import { useEffect, useRef } from 'react';
export default () => {
const isMounted = useRef(false);
useEffect(() => {
isMounted.current = true;
return () => { isMounted.current = false; };
}, []);