Skip to main content

React Native

1. Install the package

npm install @lingva/react

2. Set up with AsyncStorage

import { LingvaProvider } from '@lingva/react';
import AsyncStorage from '@react-native-async-storage/async-storage';

// Custom cache using AsyncStorage
const storageCache = {
async get(key: string) {
const value = await AsyncStorage.getItem(`lingva:${key}`);
return value ? JSON.parse(value) : null;
},
async set(key: string, value: any) {
await AsyncStorage.setItem(`lingva:${key}`, JSON.stringify(value));
},
async delete(key: string) {
await AsyncStorage.removeItem(`lingva:${key}`);
},
};

export default function App() {
return (
<LingvaProvider
config={{
apiUrl: 'https://api.lingva.dev/v1',
apiKey: 'your-api-key',
projectId: 'your-project-id',
cache: {
storage: storageCache,
ttl: 86400, // 24 hours
},
}}
>
<YourApp />
</LingvaProvider>
);
}