Javascript 在顶层再次调用render并保持可变性

Javascript 在顶层再次调用render并保持可变性,javascript,reactjs,Javascript,Reactjs,下面的测试确保组件是纯的(使用的是PureRenderMixin),我得到了以下警告 警告:setProps(…)和replaceProps(…)已弃用。相反,请在顶层再次调用render it('呈现为纯组件',()=>{ 常量对=['Trainspotting','28天后']; 常量组件=renderIntoDocument( ); 让firstButton=scryRenderedDOMComponentsWithTag(组件,'button')[0]; expect(firstButt

下面的测试确保组件是纯的(使用的是
PureRenderMixin
),我得到了以下警告

警告:setProps(…)和replaceProps(…)已弃用。相反,请在顶层再次调用render

it('呈现为纯组件',()=>{
常量对=['Trainspotting','28天后'];
常量组件=renderIntoDocument(
);
让firstButton=scryRenderedDOMComponentsWithTag(组件,'button')[0];
expect(firstButton.textContent).to.equal('trainsotting');
对[0]=“阳光”;
setProps({pair:pair});
firstButton=scryRenderedDOMComponentsWithTag(组件,'button')[0];
expect(firstButton.textContent).to.equal('trainsotting');
});

但是,如果不保持可变性,我无法重新呈现整个组件。

为第二个测试创建一个不同的/新的组件怎么样

it('renders as a pure component', () => {
  const pair = ['Trainspotting', '28 Days Later'];
  const component = renderIntoDocument(
    <Voting pair={pair} />
  );

  let firstButton = scryRenderedDOMComponentsWithTag(component,   'button')[0];
  expect(firstButton.textContent).to.equal('Trainspotting');

  pair[0] = 'Sunshine';
  const component2 = renderIntoDocument(
    <Voting pair={pair} />
  );
  firstButton = scryRenderedDOMComponentsWithTag(component2, 'button')[0];
  expect(firstButton.textContent).to.equal('Trainspotting');
});
it('呈现为纯组件',()=>{
常量对=['Trainspotting','28天后'];
常量组件=renderIntoDocument(
);
让firstButton=scryRenderedDOMComponentsWithTag(组件,'button')[0];
expect(firstButton.textContent).to.equal('Trainspotting');
对[0]=“阳光”;
常量组件2=renderIntoDocument(
);
firstButton=scryRenderedDOMComponentsWithTag(component2,‘按钮’)[0];
expect(firstButton.textContent).to.equal('trainsotting');
});
it('renders as a pure component', () => {
  const pair = ['Trainspotting', '28 Days Later'];
  const component = renderIntoDocument(
    <Voting pair={pair} />
  );

  let firstButton = scryRenderedDOMComponentsWithTag(component,   'button')[0];
  expect(firstButton.textContent).to.equal('Trainspotting');

  pair[0] = 'Sunshine';
  const component2 = renderIntoDocument(
    <Voting pair={pair} />
  );
  firstButton = scryRenderedDOMComponentsWithTag(component2, 'button')[0];
  expect(firstButton.textContent).to.equal('Trainspotting');
});