val 0.4.0

An arbitrary precision calculator language
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { useCallback, useEffect, useState } from 'react';

export function usePersistedDoc(
  key: string,
  fallback: string
): [string, (value: string) => void] {
  const [value, setValue] = useState<string>(() => {
    const stored = window.localStorage.getItem(key);

    return stored && stored.length > 0 ? stored : fallback;
  });

  useEffect(() => {
    window.localStorage.setItem(key, value);
  }, [key, value]);

  return [value, useCallback((next: string) => setValue(next), [])];
}