가정하자 나는이 <BlogEntry>
또는 <ItemEntry>
또는 <ReplyEntry>
처럼, 부모 구성 요소의 다른 유형의 여러 페이지에 걸쳐 사용됩니다 <LikePanel>
라는 작은 재사용 가능한 구성 요소 . LikePanel
의는 REDUX에 많은 작은 재사용 reactjs 구성 요소에 connect()를 사용하는 것이 좋습니다 그 것이다
import {connect} from 'react-redux'
import {likeAction} from './LikeAction'
class LikePanel extends React.Component{
render() {
return <ButtonGroup className={this.props.className}>
<Button onClick={()=>this.onClickLiking()}>
<Glyphicon glyph="thumbs-up"/>{this.props.like}</Button>
</ButtonGroup>
}
onClickLiking(type){
this.props.dispatch(likeAction());
}
}
const mapStateToProps = state => {
let obj = {};
obj[LIKE] = state[LIKE];
return obj;
}
export default connect(mapStateToProps)(LikePanel)
사용 사례 : 웹 페이지가 20 개 블로그 항목이있는 경우
가class BlogEntry extends React.Component{
render(){
return this.props.data.entry.map((item)=>{
return <div>
{item.article}
<LikePanel like={item.like}/>
</div>
}
}
}
class ProductEntry extends React.Component{
render(){
return this.props.data.entry.map((item)=>{
return <div>
<ProductPanel data={item}/>
<LikePanel like={item.like}/>
</div>
}
}
}
그래서 20가있을 것입니다 페이지에 <LikePanel>
를 연결하고, 미래의 가능성이있다 여분의 부품 것이다 redux에 연결되어 있어야합니다. <LikePanel>
과 같은 작은 구성 요소로 connect()
을 사용하는 것이 좋습니다.
부모의 '연결'에서 각 작은 구성 요소에 필요한 값을 모으고 각 하위에 직접 속성으로 전달하는 것을 고려해 볼 수 있습니다. – sdgluck