import { useState , useEffect } from "react" ; import { Store } from "./Store" ; export function useStoreBackedState < T > ( listName , key , defaultValue ) { const [ value , setValue ] = useState ( defaultValue ) ; useEffect ( ( ) => { Store . Load < T > ( listName , key ) . then ( value => { if ( value !== null ) { setValue ( value ) ; } } ) ; } , [ listName , key ] ) ; const setValueWithStore = ( newValue ) => { Store . Save ( listName , key , newValue ) ; setValue ( newValue ) ; } ; return [ value , setValueWithStore ] ; }