아래 코드가 { active, children, onClick }
의 관점에서 어떻게 작동하는지 파악하려고합니다. 여기서 중괄호는 무엇입니까? 나는 const Link = (props) =>
대신 props.active 등을 사용하여 함수에서 값에 접근 할 것을 기대했을 것입니다. 이것은 아래의 내 CommentBox 예제에서 제가하고있는 것입니다.순수 함수의 중괄호 사용
링크 :
import React, { PropTypes } from 'react'
const Link = ({ active, children, onClick }) => {
if (active) {
return <span>{children}</span>
}
return (
<a href="#"
onClick={e => {
e.preventDefault()
onClick()
}}
>
{children}
</a>
)
}
FilterLink :
import { connect } from 'react-redux'
import { setVisibilityFilter } from '../actions'
import Link from '../components/Link'
const mapStateToProps = (state, ownProps) => {
return {
active: ownProps.filter === state.visibilityFilter
}
}
const mapDispatchToProps = (dispatch, ownProps) => {
return {
onClick:() => {
dispatch(setVisibilityFilter(ownProps.filter))
}
}
}
const FilterLink = connect(
mapStateToProps,
mapDispatchToProps
)(Link)
export default FilterLink
http://redux.js.org/docs/basics/ExampleTodoList.html
CommentBox :
const CommentBox = (props) =>
<div className="commentBox">
<h1>Comments</h1>
{ props.comments.valueSeq().map((comment) =>
<Comment author={comment.author} key={comment.id}>
{comment.text}
</Comment>
)}
<CommentForm />
</div>
function mapStateToProps(state) {
return {comments: state.get('comments')};
}
'링크 = ({활성, 어린이, 온 클릭}) => {...'하고 링크 = (소품)'과 동일 => {var에 활성 = props.active, 어린이 = props.children , onClick = props.onClick; ...}'- 불리는 ** destructuring **. –