Skip to content

Commit ff17223

Browse files
committed
feat: 🎸 add persistent storage
1 parent 8a207fe commit ff17223

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

hackathon/offline-with-legend-state/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ const styles = StyleSheet.create({
4141
},
4242
});
4343

44-
// export default App;
45-
export { default } from "./.storybook";
44+
export default App;
45+
// export { default } from "./.storybook";

hackathon/offline-with-legend-state/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
"typescript": "^5.1.3"
3333
},
3434
"private": true
35-
}
35+
}
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
import { observable } from "@legendapp/state";
2+
import {
3+
configureObservablePersistence,
4+
persistObservable,
5+
} from '@legendapp/state/persist'
6+
import { ObservablePersistAsyncStorage } from '@legendapp/state/persist-plugins/async-storage'
7+
import AsyncStorage from '@react-native-async-storage/async-storage'
8+
9+
configureObservablePersistence({
10+
pluginLocal: ObservablePersistAsyncStorage,
11+
localOptions: {
12+
asyncStorage: {
13+
AsyncStorage,
14+
},
15+
},
16+
})
217

318
export const state$ = observable({
419
expenses: [
520
{ id: "1", title: "Groceries", amount: 50.0 },
621
{ id: "2", title: "Electric Bill", amount: 75.0 },
722
],
8-
});
23+
});
24+
25+
persistObservable(state$, {
26+
local: 'store',
27+
})

0 commit comments

Comments
 (0)