반응에서 redux를 사용하여 어떻게 mapStateToProps 함수 내부에서 작업을 디스패치 할 수 있습니까? 구성 요소의 렌더링이 아약스에 의해 호출되는 사용자 데이터에 크게 의존하기 때문에redux mapStateToProps 빈 상태의 ajax 호출
class Example React.Component {
render(){return (
<div>
Hello {this.state.userData.name} <--
</div>)};
);
Example.propTypes = {
id: PropTypes.number.isRequired,
};
function select(state,ownProps) {
let userData = state.user[ownProps.id];
if(!userData){//if not already in store then i want to load it
///I WANT TO dispatch an action that load this user from server.
//dispatch({type:'LOAD_USER',id: ownProps.id});
}
return {
userData
};
}
export default connect(select)(Example);
/// 사용 예 // 파견 할 수있는 권리 장소를
대신 'componentDidMount' 또는'componentWillReceiveProps'에서 보내십시오 – Deadfish
@Deadfish 유효한 포인트 .. 바보 같은 날! 고마워요 내가 게시물을 삭제하고 수치심에 숨어야하는지 궁금해! #mental_block – Zalaboza