-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathLocalStorageTest.tsx
More file actions
73 lines (64 loc) · 2.56 KB
/
LocalStorageTest.tsx
File metadata and controls
73 lines (64 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React, { useState, useEffect } from 'react';
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonButton, IonInput, IonItem, IonLabel, IonList, IonButtons, IonBackButton } from '@ionic/react';
const LocalStorageTest: React.FC = () => {
const [value, setValue] = useState('');
const [storedValue, setStoredValue] = useState<string | null>(null);
const refreshValue = () => {
const val = localStorage.getItem('inappbrowser_test_key');
setStoredValue(val);
};
useEffect(() => {
refreshValue();
}, []);
const saveValue = () => {
localStorage.setItem('inappbrowser_test_key', value);
refreshValue();
};
const clearValue = () => {
localStorage.removeItem('inappbrowser_test_key');
refreshValue();
};
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonButtons slot="start">
<IonBackButton defaultHref="/home" />
</IonButtons>
<IonTitle>LocalStorage Test</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent className="ion-padding">
<IonList>
<IonItem>
<IonLabel position="stacked">Test Value</IonLabel>
<IonInput value={value} onIonChange={(e: any) => setValue(e.detail.value!)} placeholder="Enter value to store" />
</IonItem>
</IonList>
<div style={{ marginTop: '20px' }}>
<IonButton expand="block" onClick={saveValue}>Save to LocalStorage</IonButton>
<IonButton expand="block" color="light" onClick={refreshValue}>Refresh from LocalStorage</IonButton>
<IonButton expand="block" color="danger" onClick={clearValue}>Clear LocalStorage</IonButton>
</div>
<div style={{ marginTop: '40px' }}>
<h3>Stored Value:</h3>
<p style={{ fontSize: '24px', fontWeight: 'bold' }}>{storedValue || '(none)'}</p>
</div>
<div style={{ marginTop: '20px', padding: '10px', backgroundColor: '#f0f0f0', borderRadius: '8px' }}>
<p><strong>Instructions:</strong></p>
<ol>
<li>Set a value here in the main app.</li>
<li>Go back and open this same page using "Open Site (InAppBrowser)".</li>
<li>Use the <strong>Enable Storage Isolation</strong> toggle to test different modes.
<ul>
<li><strong>On (Default)</strong>: Value should be "(none)".</li>
<li><strong>Off</strong>: Value should be shared.</li>
</ul>
</li>
</ol>
</div>
</IonContent>
</IonPage>
);
};
export default LocalStorageTest;