구성 요소 인 Parent를 가져 와서 다른 구성 요소 인 Child를 주입합니다.Redux를 사용하여 상위 구성 요소의 하위 구성 요소를 읽는 중
class Parent extends Component {
render(){
//something like this
<div className={this.props.children.foo}>
{this.props.children}
</div>
}
@edit
후 :
이function mapStateToProps(state) {
return {
foo : 'some-value'
}
}
내가 요소 그런 부모에 foo
으로 접근하고 싶습니다 :
아이는 다음과 같이 정의 소품을 가지고 이것을 사용하여 React.Children.toArray
나는 자식을 배열로 가져 왔고 forEach
-it입니다.
그러나 소품은 child.props
에 없습니다.
누락 된 것이 있습니다. 누구나 아이디어가 있으십니까? 그것은
render() {
this.props.children.forEach((component) => {
console.log(component.props.foo);
})
return ...;
}
에 루프가 this
네,하지만 mapStateToProps 반환 No 재산권 –
안녕하세요, 개발자 도구 반응하여 내가 사용 항상 연결 구성 요소가 될 것 'this.props.children'돌아 오는 것을이 눈치없는 내가 (반응-REDUX 라이브러리 참조) 실제 문제는 정의한 구성 요소 인 Connect의 하위 항목을 얻는 것입니다. –
연결 메서드에는 "withRef"옵션이 있습니다. 기본적으로 래핑 된 구성 요소에 액세스하게됩니다. 기본값은 false입니다. https://github.com/reactjs/react-redux/blob/master/docs/api.md –