react-component / react-component/tree
needSync的逻辑处理
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 490
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 5
Description
使用场景: 右键点击某个节点,左键点击了一个新建文件夹,这时会在当前节点子级新建文件夹,我会获取到当前节点的props,并把其key设置到expandedKeys中,让当前节点自动展开(此时并没有通过点击事件来触发展开)
问题: key已经正确设定了,tree的props中新的expandedKeys也有了,但是state中的expandedKeys还是[], 所以树没有展开
看了下代码:
function needSync(name) {
return (!prevProps && name in props) || (prevProps && prevProps[name] !== props[name]);
}
我感觉这里有问题,我把这个方法改了下,如果name中包含Keys,只要传值就返回true
function needSync(name) {
if (name.indexOf('Keys') > -1) {
return prevProps && prevProps[name];
}
return (!prevProps && name in props) || (prevProps && prevProps[name] !== props[name]);
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the needSync(name) function in the tree component and trace how expandedKeys moves from props into state. Reproduce the external expansion scenario described in the issue, then verify that state updates when expandedKeys changes without a click event.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100