Skip to content

Instantly share code, notes, and snippets.

@CADBOT
Created May 24, 2016 17:08
Show Gist options
  • Save CADBOT/25df90d37bff9e81c6e82de247970531 to your computer and use it in GitHub Desktop.
Save CADBOT/25df90d37bff9e81c6e82de247970531 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity
} from 'react-native';
class TodosList extends Component {
render() {
var key = 0
var todosJsx = this.props.todoData.map(todo => {
return <Text>{todo}</Text>})
return (
<View>
{todosJsx}
</View>
)
}
}
class Submit extends Component {
render() {
return (
<TouchableOpacity
onPress={() => this.props.addTodo('new todo')}
>
<Text>Submit</Text>
</TouchableOpacity>
)
}
}
class TodoAppOne extends Component {
constructor(props) {
super(props)
this.state = {
todoData: [
'learn react',
'learn flexbos'
]
}
}
addTodo() {
var todo = 'learn more!'
this.setState({
todoData: this.state.todoData.concat(todo)
})
}
render() {
return (
<View style={styles.container}>
<Text>Todo App</Text>
<TodosList todoData={this.state.todoData}/>
<Submit addTodo={this.addTodo.bind(this)}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('TodoAppOne', () => TodoAppOne);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment