【发布时间】:2018-01-25 18:30:13
【问题描述】:
我正在渲染 RootComponent:
//RENDERING ROOT COMPONENT-------------------------------------------------------------------------------
ReactDOM.render(
<Provider store={store}>
<RootComponent />
</Provider>,
document.getElementById('app'));
//RENDERING ROOT COMPONENT-------------------------------------------------------------------------------
RootComponent只有一个容器:
//ROOT COMPONENT----------------------------------------------------------------------------------------------------
const RootComponent = () => (
<div>
<BookListContainer />
</div>
);
//ROOT COMPONENT----------------------------------------------------------------------------------------------------
BooklistContainer:
//BOOKLIST CONTAINER-------------------------------------------------------------------------------------------------------
class BookListContainer extends Component{
componentWillMount(){
console.log('componentWillMount executing...');
() => this.props.ajaxRequestTriggeredMethod();
}
render() {
return (
<div>
<BooksList DataInputParam={this.props.books} BtnClickHandler={this.props.buttonClickedMethod} />
</div>
);
}
}
const mapStateToProps = (state) => {
return{
books: state.BooksReducer
};
};
const mapDispatchToProps = (dispatch) => {
return {
buttonClickedMethod: () => dispatch({type: 'BUTTON_CLICKED'}),
ajaxRequestTriggeredMethod: () => console.log('ajaxRequestTriggeredMethod is consoled...')
};
};
connect(mapStateToProps, mapDispatchToProps)(BookListContainer);
//BOOKLIST CONTAINER-------------------------------------------------------------------------------------------------------
目前所有组件都在一个 js 文件中,所以我不会导出/导入除标准库之外的任何内容...
结果:我在控制台中收到 'componentWillMount execution...' 消息,但 不是 得到 'ajaxRequestTriggeredMethod is concond...' 消息。此外,控制台中不会显示任何错误。
【问题讨论】:
标签: reactjs redux react-redux