이어서 카운터 컴포넌트와 카운터 컨테이너 컴포넌트를 만듭니다. 프레젠테이셔널 컴포넌트는 components 디렉터리에 저장하고, 컨테이너 컴포넌트는 containers 디렉터리에 저장하세요.
components/Counter.js
import React from 'react'; const Counter = ({ onIncrease, onDecrease, number }) => { return ( <div> <h1>{number}</h1> <button onClick={onIncrease}>+1</button> <button onClick={onDecrease}>-1</button> </div> ); }; export default Counter;
containers/CounterContainer.js
import React from 'react'; import { connect } from 'react-redux'; import { increase, decrease } from '../modules/counter'; import Counter from '../components/Counter'; const CounterContainer = ({ number, increase, decrease }) => { return ( <Counter number={number} onIncrease={increase} onDecrease={decrease} /> ); }; export default connect( state => ({ number: state.counter }), { increase, decrease } )(CounterContainer);