第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何維護Sortable容器的子組件的狀態(tài)?

如何維護Sortable容器的子組件的狀態(tài)?

胡子哥哥 2021-09-04 17:37:16
如下面的代碼所示,App 組件有一個狀態(tài)。這個狀態(tài)的屬性通過 props 傳遞給子組件。但是一旦 App 組件中的狀態(tài)發(fā)生變化,Sortable 組件內(nèi)的子組件就不會更新。但是這個 Sortable 容器之外的子組件會像往常一樣更新(重新渲染)。如何在每次狀態(tài)更改時呈現(xiàn)這些可排序的子組件?這是代碼(簡化):應用程序.js:import Sortable from 'react-sortablejs';import Child from './Child';class App extends React.Component {  constructor(props) {    super(props);    this.state = {      text1: "Text1",      text2: "Text2"    }  }  render() {    return (      <div className="App">        <Sortable>          <Child text={this.state.text1} />          <Child text={this.state.text2} />        </Sortable>        <Child text={this.state.text1} />      </div>    );  }}Child.js:從“反應”導入反應;export default class Child extends React.Component {    constructor(props) {        super(props);    }    render() {        return (<p>{this.props.text}</p>)    }}頁面加載時的樣子:...在狀態(tài)更新后:
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經(jīng)驗 獲得超6個贊

看起來Sortable組件shouldComponentUpdate 在這里覆蓋:


shouldComponentUpdate(nextProps) {

    // If onChange is null, it is an UnControlled component

    // Don't let React re-render it by setting return to false

    if (!nextProps.onChange) {

         return false;

    }

    return true;

}

基本上,它設置為僅在有onChange處理程序時才更改。您希望傳遞這樣的方法來確定當狀態(tài)發(fā)生App變化時要做什么(如果有的話)。


查看完整回答
反對 回復 2021-09-04
  • 1 回答
  • 0 關注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號