mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
swapped it back to react-redux
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import React from 'react';
|
||||
import { DefaultButton, Stack, Text } from 'office-ui-fabric-react';
|
||||
import { actions } from '../actions';
|
||||
import { useMappedState, useDispatch } from 'redux-react-hook';
|
||||
import { connect } from 'react-redux';
|
||||
import { Store } from '../store';
|
||||
|
||||
export const TodoFooter = () => {
|
||||
const { todos } = useMappedState(state => state);
|
||||
const dispatch = useDispatch();
|
||||
interface TodoFooterProps {
|
||||
todos: Store['todos'];
|
||||
clear: () => void;
|
||||
}
|
||||
|
||||
const TodoFooter = (props: TodoFooterProps) => {
|
||||
const { todos, clear } = props;
|
||||
|
||||
const itemCount = Object.keys(todos).filter(id => !todos[id].completed).length;
|
||||
|
||||
@@ -14,7 +19,18 @@ export const TodoFooter = () => {
|
||||
<Text>
|
||||
{itemCount} item{itemCount === 1 ? '' : 's'} left
|
||||
</Text>
|
||||
<DefaultButton onClick={() => dispatch(actions.clear())}>Clear Completed</DefaultButton>
|
||||
<DefaultButton onClick={() => clear()}>Clear Completed</DefaultButton>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
const ConnectedTodoFooter = connect(
|
||||
(state: Store) => ({
|
||||
todos: state.todos
|
||||
}),
|
||||
dispatch => ({
|
||||
clear: () => dispatch(actions.clear())
|
||||
})
|
||||
)(TodoFooter);
|
||||
|
||||
export { ConnectedTodoFooter as TodoFooter };
|
||||
|
||||
Reference in New Issue
Block a user