Skip to content

Instantly share code, notes, and snippets.

@pi-chan
Created May 3, 2018 21:44
Show Gist options
  • Save pi-chan/b46cba2e316b260ba6060557ddce86e8 to your computer and use it in GitHub Desktop.
Save pi-chan/b46cba2e316b260ba6060557ddce86e8 to your computer and use it in GitHub Desktop.
mobx-persist導入の差分
diff --git a/App.js b/App.js
index 411a196..5b9d526 100644
--- a/App.js
+++ b/App.js
@@ -6,15 +6,24 @@
import React, { Component } from 'react';
import { Provider } from 'mobx-react';
+import { create } from 'mobx-persist';
+import { AsyncStorage } from 'react-native';
import TodoStore from './src/TodoStore';
import TodoScreen from './src/TodoScreen';
+const hydrate = create({
+ storage: AsyncStorage,
+ jsonify: true,
+});
+
const todoStore = new TodoStore();
const stores = {
todo: todoStore,
};
+hydrate('todos', todoStore);
+
type Props = {};
export default class App extends Component<Props> {
render() {
diff --git a/src/TodoStore.js b/src/TodoStore.js
index 31e1635..c0505ba 100644
--- a/src/TodoStore.js
+++ b/src/TodoStore.js
@@ -1,6 +1,8 @@
import { observable, action } from 'mobx';
+import { persist } from 'mobx-persist';
export default class TodoStore {
+ @persist('list')
@observable todos = [];
@action.bound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment