-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
62 lines (53 loc) · 1.47 KB
/
main.js
File metadata and controls
62 lines (53 loc) · 1.47 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React from 'react'
import {
AppRegistry,
AsyncStorage,
} from 'react-native'
import { createStore, compose, applyMiddleware } from 'redux'
import thunk from 'redux-thunk';
import { Provider } from 'react-redux'
import { persistStore, autoRehydrate } from 'redux-persist'
import App from './components/App'
import { Title } from './components/Common'
import reducers from './reducers'
class AppWithStore extends React.Component {
state: {
ready: boolean,
}
store: any
constructor(props) {
super(props)
this.state = {
ready: false,
}
this.store = createStore(reducers, applyMiddleware(thunk),
compose(autoRehydrate()))
persistStore(this.store, {
whitelist: ['test'],
storage: AsyncStorage,
}, () => {
console.log('Rehydration completed')
// TODO: Please REMOVE!
// Slow it down to show, loading message
setTimeout(() => {
this.setState({ready: true})
}, 1000)
});
}
render() {
if (!this.state.ready) {
return <Title>Loading...</Title>
}
return (
<Provider store={this.store}>
<App />
</Provider>
)
}
}
AppRegistry.registerComponent('SampleMobileApp', () => AppWithStore)