Skip to content

Instantly share code, notes, and snippets.

@albttx
Created October 23, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albttx/bf8e3b6df31872f60427cd9bed251eac to your computer and use it in GitHub Desktop.
Save albttx/bf8e3b6df31872f60427cd9bed251eac to your computer and use it in GitHub Desktop.
React Native simple mobx
import React from 'React';
import { View, Button, Text } from 'react-native';
import { observable, computed, action } from 'mobx';
import { observer } from 'mobx-react';
class _TodosService {
i = 1
@observable todos = [
{name: "Test_0", done: false}
]
@computed get todosList() {
return this.todos
}
@action addTodo() {
this.todos.push({name: "Test_" + this.i++, done: false})
}
}
const TodosService = new _TodosService();
@observer
export default class App extends React.Component {
render() {
return (
<View style={{paddingTop: 30}}>
<Button onPress={ () => TodosService.addTodo() }>
<Text>Add todos</Text>
</Button>
<Text>{ JSON.stringify( TodosService.todosList ) }</Text>
</View>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment