同求 我贴代码你看一下
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.