Connecting with Redux

The main file that binds everything, app.js, is given as follows. The App component acts as the root file:

import React, { PureComponent } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";

import TodoList from "./TodoList";
import AddTodo from "./AddTodo";
import Footer from "./Footer";

class App extends PureComponent {
static propTypes = {
activeFilter: PropTypes.string.isRequired,
todoList: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired
};

render() {
const { dispatch, activeFilter, todoList } = this.props;
return (
<div className="app">
<div className="todos">
<h1>Rask Lege TODO App</h1>
<AddTodo dispatch={dispatch} />
<TodoList
dispatch={dispatch}
activeFilter={activeFilter}
todoList={todoList}
/>
<Footer dispatch={dispatch} activeFilter={activeFilter} />
</div>
</div>
);
}
}

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

export default connect(mapStateToProps)(App);

To run the code, follow these steps:

yarn install
yarn start
# This should start the application at:
Local: http://localhost:3000/
On Your Network: http://10.0.20.219:3000/

Try to create some notes, mark it as done, and use the filter to see how it works.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset