我SettingsTab
在一个名为的包装器中呈现一个React组件TeamView
.它的API看起来像
class TeamView {
constructor() {
this.el = document.createElement('div');
}
render() {
ReactDOM.render(<SettingsTab/>, this.el);
return this;
}
remove() {
this.el.remove();
}
}
Run Code Online (Sandbox Code Playgroud)
用过类似的东西
// to present the team view
const teamView = new TeamView();
document.body.appendChild(teamView.render().el);
// to remove the team view
teamView.remove();
Run Code Online (Sandbox Code Playgroud)
我想知道的是,在打电话之前应该TeamView#remove
打电话ReactDOM. unmountComponentAtNode(this.el)
this.el.remove()
吗?
我可以在网络上找到的示例使得看起来unmountComponentAtNode
只需要在容器将保留在DOM中时才需要调用它; 并且新的门户示例只是删除容器,而不调用unmountComponentAtNode
.
但是,我不确定这是否特别,因为它正在使用门户网站,而且这篇帖子让人觉得打电话总是好的做法unmountComponentAtNode
.
我的应用程序提供了一个类似于 Apple 的表情符号键盘,其中表情符号按类别显示。我使用一个集合视图来呈现它,其中类别是部分。如果最近插入了表情符号,它应该出现在“常用”类别以及它通常所在的任何类别中。
这对我试图将我的集合视图转换为使用 a 来说是一个问题UICollectionViewDiffableDataSource
,因为NSDiffableDataSourceSnapshot
要求项目是唯一的。如果我做类似的事情
let snapshot = NSDiffableDataSourceSnapshot<Section, Emoji>()
snapshot.appendItems([thumbsUpEmoji], toSection: .frequents)
snapshot.appendItems([thumbsUpEmoji], toSection: .smileys)
dataSource.apply(snapshot)
Run Code Online (Sandbox Code Playgroud)
我收到类似的警告
插入的标识符已经存在;现有项目将被移动到此当前插入的位置。请注意,如果插入时项目不是唯一的,这将影响性能。
表情符号只出现在一个部分,而不是两个部分。如何将项目插入多个部分?