求助一个关于子组件setState的问题

#1

我现在写了的一个父组件,为类似Steps的导航组件,里面每一步需要写内容,内容也是组件。现在碰到一个问题,就是如果内容组件里有用到setState()话,就会报warning,详细内容为

warning.js:36 Warning: setState(...): Cannot update during an existing state transition (such as within `render` or 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`.

这个是因为我的子组件里面有用setState造成的么?如果是这样,我的子组件不能使用setState()么?那么子组件感觉是不是就比较鸡肋了=-=

#2

你是不是把setState放在了render函数里面了

#3

没代码怎么说 代码贴出来

#4

同求 我贴代码你看一下

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 withinrenderor 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 tocomponentWillMount.