Action Shorthand Notation - seowonintech/react-native-todo-list GitHub Wiki
์ VisibleTodoList.js์์ toggleTodo์๋ dispatch๋ฅผ ์ ์ฉํ์ง ์์์๊น? ๋ค๋ฅธ action๋ค์์๋ ๋ชจ๋ dispatch๋ฅผ ์ผ๋๋ฐ....
์๋ ๋งํฌ์์ ์ค๋ช ์ ์ ๋ณผ ์ ์์. ์๋ ์ฌ์ดํธ์ ์๊ฐ๋ณด๋ค ์ข์ ํ์ด ๋ง์. ์๊ฐ๋๋ฉด ๊ผญ ์ฝ์ด๋ณผ ํ์๊ฐ ์์ ๋ฏ.
mapDispatchToProps shorthand notation
mapDispatchToProps์์ ์ฐ๊ฒฐํ๋ ค๋ ํจ์์ actions์ ์๋ ํจ์์ Parameter๊ฐ ์ ํํ๊ฒ ์ผ์นํ๋ฉด ํด๋น ๋ฐฉ๋ฒ์ผ๋ก ์๋ต์ด ๊ฐ๋ฅํจ.
์ ๊ฑธ ์ด์ง ํ์ด์ฐ๋ฉด github์ ์๋ ์ฝ๋๊ฐ ๋๋ ๊ฒ์.
const mapDispatchToProps = (dispatch) => ({
onTodoClick(id) {
dispatch(toggleTodo(id));
},
});
const VisibleTodoList = withRouter(connect(
mapStateToProps,
mapDispatchToProps
)(TodoList));const VisibleTodoList = withRouter(connect(
mapStateToProps,
{ onTodoClick: toggleTodo }
)(TodoList));