ReactJs 0.14-不变冲突:addComponentAsRefTo(…):只有ReactOwner可以有引用

ReactJs 0.14-不变冲突:addComponentAsRefTo(…):只有ReactOwner可以有引用,reactjs,Reactjs,下面的解决方案… 我有一个动画组件: const CSSAnimation = require('./cssanimation.js'); export default class Animation extends Component { .............. componentWillMount() { let clientId = this.props.clientId; this.createSlideShow(clientId)

下面的解决方案…

我有一个动画组件:

const CSSAnimation = require('./cssanimation.js');

export default class Animation extends Component {

     ..............

    componentWillMount() {
    let clientId = this.props.clientId;
    this.createSlideShow(clientId)
    }

   createSlideShow(clientId) {
    let results = [];
    slides.map(function (slide, index) {
        results.push(
            <div key={ index } className="slide" ref="slide">
            .......
            </div>
         );
    }.bind(this));
    this.setState({slideShow: results});
    let slideRef = this.refs.slide;  <--- returns undefined
    new CSSAnimation(slideRef)

     ...........................
1. The application has multiple react modules in the build.
2. The ref attribute is not being used w/in the render method.
const CSSAnimation=require('./CSSAnimation.js');
导出默认类动画扩展组件{
..............
组件willmount(){
让clientId=this.props.clientId;
this.createSlideShow(clientId)
}
创建幻灯片(clientId){
让结果=[];
幻灯片.地图(功能(幻灯片,索引){
结果:推(
.......
);
}.约束(这个);
this.setState({slideShow:results});
设slideRef=this.refs.slide;
我根据文档收到的错误出现在以下两个原因之一:

const CSSAnimation = require('./cssanimation.js');

export default class Animation extends Component {

     ..............

    componentWillMount() {
    let clientId = this.props.clientId;
    this.createSlideShow(clientId)
    }

   createSlideShow(clientId) {
    let results = [];
    slides.map(function (slide, index) {
        results.push(
            <div key={ index } className="slide" ref="slide">
            .......
            </div>
         );
    }.bind(this));
    this.setState({slideShow: results});
    let slideRef = this.refs.slide;  <--- returns undefined
    new CSSAnimation(slideRef)

     ...........................
1. The application has multiple react modules in the build.
2. The ref attribute is not being used w/in the render method.
我的问题是#2

我将整个createSlideShow()方法的内容移动到了渲染函数中,但随后发生了另一个错误:您无法更新渲染函数中的状态w/

所以,对我来说,我取消了state.slideShow,只处理结果,如下所示

render() {

      let results = [];
      slides.map(function (slide, index) {
        results.push(
        <div key={ index } className="slide" ref="slide">
        .......
        </div>
      );
     }.bind(this));

   return (
        <div id="Animation" className="datatable sam" ref="Animation">
            { results }
        </div>
    )
  }


   componentDidMount() {
       let slideRef = this.refs.slide; // returns back with "slideRef = div.slide"     
       new CSSAnimation(slideRef);
   }
render(){
让结果=[];
幻灯片.地图(功能(幻灯片,索引){
结果:推(
.......
);
}.约束(这个);
返回(
{results}
)
}
componentDidMount(){
让slideRef=this.refs.slide;//返回“slideRef=div.slide”
新CSSAnimation(slideRef);
}