Last active
February 23, 2018 01:01
-
-
Save dbuarque/0314d629b60c3778a6a1bb1a23c4f46a to your computer and use it in GitHub Desktop.
Mobx Basic Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": ["react-native"], | |
"plugins": ["transform-decorators-legacy"] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { | |
View | |
} from 'react-native'; | |
import { Provider } from 'mobx-react'; | |
import HomeScreen from './screens/HomeScreen' | |
import store from './store'; | |
export default App = () => ( | |
<Provider appStore={store}> | |
<HomeScreen></HomeScreen> | |
</Provider> | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { | |
View | |
} from 'react-native'; | |
import Modal from 'react-native-modal'; | |
import { observer, inject } from "mobx-react";] | |
import { Screen } from './../shared' | |
// Use inject from any Component to connect on the store | |
@inject("appStore") @observer | |
class HomeScreen extends Component { | |
toggleModal = () => { | |
const { appStore } = this.props; | |
appStore.set('isModalVisible', !appStore.get('isModalVisible')); | |
} | |
render() { | |
const isModalVisible = this.props.appStore.get('isModalVisible'); | |
return ( | |
<Modal isVisible={isModalVisible}> | |
<View><View/> | |
</Modal> | |
); | |
} | |
} | |
export default HomeScreen; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { observable } from 'mobx'; | |
const initialState = { | |
isModalVisible: false | |
} | |
export default observable.map(initialState); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment