问题描述
既然 React 有自己的 DOM 副本,那么在不影响 React 的虚拟 DOM(性能)的情况下修改 HTML 元素的属性的最佳方法是什么?
假设我想根据 active
的可见性(Intersection Observer)在从 div
列表中添加和删除 if (inView) {
element.classList.add('active')
} else {
element.classList.remove('active')
}
类之间切换
在 Javascript 中我可以做到:
# read both files
with open('file_one.txt') as f:
file_one = f.read().splitlines()
with open('file_two.txt') as f:
file_two = f.read().splitlines()
# method 1 by stephan berger:
result = list(set(file_one)^set(file_two))
# method 2:
for idx_one,line_one in enumerate(file_one):
for idx_two,line_two in enumerate(file_two):
if line_two == line_one:
print(f"Removing duplicate: {line_two}")
file_one.pop(idx_one)
# write new file
with open("output.txt","w") as f:
for line in result: # file_one for method 2
f.write(line + "\n")
print("Generated output.txt")
这会影响 React 的虚拟 DOM 吗?如果是,你能提出更好的方法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)