|
@@ -1,49 +1,20 @@
|
|
|
-import * as React from 'react';
|
|
|
-import { connect } from 'react-redux';
|
|
|
-import { AppState } from './store';
|
|
|
-
|
|
|
-import { CounterState } from './store/counter/types';
|
|
|
-import { increment, decrement, reset } from './store/counter/actions';
|
|
|
-
|
|
|
-import Counter from './components/Counter';
|
|
|
-
|
|
|
-interface AppProps {
|
|
|
- counter: CounterState;
|
|
|
- increment: typeof increment;
|
|
|
- decrement: typeof decrement;
|
|
|
- reset: typeof reset;
|
|
|
-}
|
|
|
-
|
|
|
-class App extends React.Component<AppProps> {
|
|
|
- increment = () => {
|
|
|
- this.props.increment();
|
|
|
- };
|
|
|
-
|
|
|
- decrement = () => {
|
|
|
- this.props.decrement();
|
|
|
- };
|
|
|
-
|
|
|
- reset = () => {
|
|
|
- this.props.reset();
|
|
|
- };
|
|
|
-
|
|
|
- render() {
|
|
|
- return (
|
|
|
- <Counter
|
|
|
- value={this.props.counter.value}
|
|
|
- onIncrement={this.increment}
|
|
|
- onDecrement={this.decrement}
|
|
|
- onReset={this.reset}
|
|
|
- />
|
|
|
- );
|
|
|
- }
|
|
|
+import {useDispatch, useSelector} from "react-redux";
|
|
|
+import {CounterTypes} from "./reducers/types";
|
|
|
+import "./index.sass";
|
|
|
+import { RootState } from "./reducers";
|
|
|
+
|
|
|
+function App() {
|
|
|
+ const dispatch = useDispatch();
|
|
|
+ const value = useSelector((state:RootState) => state.counter);
|
|
|
+
|
|
|
+ return(
|
|
|
+ <>
|
|
|
+ <h2> Counter: {value}</h2>
|
|
|
+ <button className="btn_click" onClick={() => dispatch({type: CounterTypes.ACTION_TYPE_INCREMENT})}>+</button>
|
|
|
+ <button className="btn_click" onClick={() => dispatch({type: CounterTypes.ACTION_TYPE_DECREMENT})}>-</button>
|
|
|
+ </>
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-const mapStateToProps = (state: AppState) => ({
|
|
|
- counter: state.counter
|
|
|
-});
|
|
|
+export default App;
|
|
|
|
|
|
-export default connect(
|
|
|
- mapStateToProps,
|
|
|
- { increment, decrement, reset }
|
|
|
-)(App);
|