Migrate useStoredLayout to TypeScript. (#3267)

This commit is contained in:
Corey Farwell
2025-12-05 08:43:09 -05:00
committed by GitHub
parent 6a3d5bc533
commit 78d95dfa4e

View File

@@ -1,18 +1,23 @@
// @flow
import { useCallback, useEffect, useState } from "react";
import { zustandStorage } from "stores/useStore";
const useStoredLayout = ( storageKey: string ): Object => {
const [layout, setLayout] = useState( null );
interface LayoutHook {
layout: string | null;
writeLayoutToStorage: ( newValue: string ) => void;
}
const writeLayoutToStorage = useCallback( newValue => {
const useStoredLayout = ( storageKey: string ): LayoutHook => {
const [layout, setLayout] = useState<string | null>( null );
const writeLayoutToStorage = useCallback( ( newValue: string ) => {
zustandStorage.setItem( storageKey, newValue );
setLayout( newValue );
}, [storageKey] );
useEffect( ( ) => {
const readLayoutFromStorage = async ( ) => {
const storedLayout = zustandStorage.getItem( storageKey );
// Casting is necessary because zustandStorage.getItem returns string | number | null
const storedLayout = zustandStorage.getItem( storageKey ) as string | null;
const defaultLayout = storageKey === "exploreObservationsLayout"
? "map"
: "grid";