mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2025-12-23 22:18:36 -05:00
Migrate useStoredLayout to TypeScript. (#3267)
This commit is contained in:
@@ -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";
|
||||
Reference in New Issue
Block a user