import React , {Component, PropTypes} from "react" ;
import {Link} from 'react-router' ;
import {connect} from 'react-redux';
import {listProducts,destroyProduct} from "../../actions/productAction";
@connect(state=> {
return {all: state.product.all,params:state.router.params}
})
export default class ProductList extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
this.props.dispatch(listProducts());
}
render() {
const {all} = this.props;
return <div className="container-wrapper">
{ all.map(item => {
return <Link to={`/products/${item.id}`} className="item" key={item.id}>
<div>
<p>产品名称</p>
<p>{item.name}</p>
</div>
</Link>
}) }
</div>;
}
}
warning.js:44 Warning: setState(...): Cannot update during an existing state transition (such as within
renderor another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to
componentWillMount.
而且非常疑惑的是 为什么url会直接改变。
原先的列表 比如说存在 ProductA ProductB ProductC url分别是 product/a product/b product/c。
但是无论点击哪个 都会跳转到product/a 这个URL。
手动 输入product/b 调试时候发现url 会突然 变成 product/a