@easyappkit/local-storage
v1.0.0
Published
Local storage management with AsyncStorage and SecureStore for Easy App Kit
Maintainers
Readme
@easyappkit/local-storage
Local storage management with AsyncStorage and SecureStore for Easy App Kit.
Installation
npm install @easyappkit/local-storage @react-native-async-storage/async-storage expo-secure-storeUsage
AsyncStorage Hooks
import { useAsyncStorage } from '@easyappkit/local-storage';
function Settings() {
const { value, save, remove, loading } = useAsyncStorage('theme', 'light');
if (loading) return <Text>Loading...</Text>;
return (
<View>
<Text>Theme: {value}</Text>
<Button onPress={() => save('dark')}>Set Dark</Button>
<Button onPress={remove}>Clear</Button>
</View>
);
}
// With objects
function UserSettings() {
const { value, save } = useAsyncStorage<{ notifications: boolean }>('settings', {
notifications: true
});
return <Switch value={value?.notifications} onValueChange={(v) => save({ notifications: v })} />;
}SecureStore Hooks (for sensitive data)
import { useSecureStorage } from '@easyappkit/local-storage';
function AuthToken() {
const { value, save, remove } = useSecureStorage<string>('auth_token');
return (
<Button onPress={() => save('secret-token')}>Save Token</Button>
);
}Direct API
import { getItem, setItem, removeItem, getObject, setObject } from '@easyappkit/local-storage';
// Strings
await setItem('key', 'value');
const value = await getItem('key');
await removeItem('key');
// Objects
await setObject('user', { name: 'John', age: 30 });
const user = await getObject<{ name: string; age: number }>('user');Secure Storage API
import { getSecureItem, setSecureItem, deleteSecureItem } from '@easyappkit/local-storage';
await setSecureItem('token', 'secret-value');
const token = await getSecureItem('token');
await deleteSecureItem('token');License
MIT
