11import React , { useEffect } from 'react' ;
22import PropTypes from 'prop-types' ;
3+ import { useSelector , useDispatch } from 'react-redux' ;
34
45import 'todomvc-app-css/index.css' ;
56
6- import Header from '../containers/Header' ;
7- import MainSection from '../containers/MainSection' ;
8- import Footer from '../containers/Footer' ;
7+ import Header from './Header' ;
8+ import MainSection from './MainSection' ;
9+ import Footer from './Footer' ;
10+
11+ import {
12+ getCompletedTodoCount ,
13+ getActiveTodoCount ,
14+ getTodosCount ,
15+ } from '../selectors' ;
16+ import { fetchTodos } from '../actions' ;
917
1018import * as types from '../constants/TodoFilters' ;
1119
12- const App = ( {
13- fetchTodos ,
14- todosCount ,
15- activeTodoCount ,
16- completedCount ,
17- nowShowing ,
18- } ) => {
20+ const App = ( { nowShowing } ) => {
21+ const todosCount = useSelector ( getTodosCount ) ;
22+ const activeTodoCount = useSelector ( getActiveTodoCount ) ;
23+ const completedCount = useSelector ( getCompletedTodoCount ) ;
24+
25+ const dispatch = useDispatch ( ) ;
26+
1927 useEffect ( ( ) => {
20- fetchTodos ( ) ;
21- } , [ fetchTodos ] ) ;
28+ dispatch ( fetchTodos ( ) ) ;
29+ } , [ dispatch ] ) ;
2230
2331 return (
2432 < section className = "todoapp" >
@@ -36,15 +44,11 @@ App.defaultProps = {
3644} ;
3745
3846App . propTypes = {
39- fetchTodos : PropTypes . func . isRequired ,
4047 nowShowing : PropTypes . oneOf ( [
4148 types . ALL_TODOS ,
4249 types . ACTIVE_TODOS ,
4350 types . COMPLETED_TODOS ,
4451 ] ) ,
45- todosCount : PropTypes . number . isRequired ,
46- activeTodoCount : PropTypes . number . isRequired ,
47- completedCount : PropTypes . number . isRequired ,
4852} ;
4953
5054export default App ;
0 commit comments