Ajout traque-app

This commit is contained in:
Sebastien Riviere
2025-08-24 10:30:32 +02:00
parent 623d1c05bf
commit a7f047388f
72 changed files with 45125 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import AsyncStorage from '@react-native-async-storage/async-storage';
import { useEffect, useState } from "react";
export function useLocalStorage(key, initialValue) {
const [storedValue, setStoredValue] = useState(initialValue);
const [loading, setLoading] = useState(true);
useEffect(() => {
async function fetchData() {
try {
const item = await AsyncStorage.getItem(key);
setStoredValue(item ? JSON.parse(item) : initialValue);
} catch (error) {
console.log(error);
}
setLoading(false);
}
fetchData();
}, []);
const setValue = async value => {
try {
setLoading(true);
const valueToStore = value instanceof Function ? value(storedValue) : value;
setStoredValue(valueToStore);
await AsyncStorage.setItem(key, JSON.stringify(valueToStore));
setLoading(false);
} catch (error) {
console.log(error);
}
}
return [storedValue, setValue, loading];
}