Skip to content

Commit

Permalink
listing todos
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogerd Júnior Ribeiro Bitarães committed Jan 15, 2019
1 parent 258c098 commit b51c181
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/TodoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";

import { View, Text } from "react-native";
import { connect } from "react-redux";

const TodoList = ({ todos }) => (
<View>
{todos.map(todo => (
<Text>{todo}</Text>
))}
</View>
);

const mapStateToProps = state => ({
todos: state.todos
});

export default connect(mapStateToProps)(TodoList);
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React from "react";
import { Text, View } from "react-native";
import { Provider } from "react-redux";
import store from "./store";
import TodoList from "./TodoList";

const App = () => (
<Provider store={store}>
<View>
<Text>Home</Text>
<TodoList />
</View>
</Provider>
);
Expand Down
3 changes: 2 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createStore } from "redux";
import reducers from "./reducers";

const store = createStore(() => {});
const store = createStore(reducers);

export default store;
6 changes: 6 additions & 0 deletions src/store/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { combineReducers } from "redux";

import todos from "./todos";
export default combineReducers({
todos
});
10 changes: 10 additions & 0 deletions src/store/reducers/todos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const INITIAL_STATE = ["fazer café", "estudar react native"];

export default function todos(state = INITIAL_STATE, action) {
switch (action.type) {
case "ADD_TODO":
return [...state, action.text];
default:
return state;
}
}

0 comments on commit b51c181

Please sign in to comment.