父組件state改變遏片,子組件未重新渲染
state: any = {
folders: [],
files: []
};
sort = () => {
const newFolders = sortWay(this.state.folders);
const newFiles = sortWay(this.state.files);
this.setState({
folders: newFolders,
files: newFiles
})
}
return (
<Son sort={this.sort} folders={this.state.folders} files={this.state.files} />
)
- 子組件調(diào)用該排序方法撮竿,父組件state改變吮便,但子組件不會重新渲染。
解決
return (
<Son sort={this.sort} folders={[...this.state.folders]} files={[...this.state.files]} />
)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者