Skip to content

Commit

Permalink
fix(SearchTree): 组件内部内部回调函数在闭包环境中,导致回调函数中无法拿到最新值 #593 (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr-z committed Mar 3, 2022
1 parent 30fc5a7 commit 61a9651
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/react-search-tree/src/SearchTagInput.tsx
Expand Up @@ -117,7 +117,7 @@ function SearchTagInput<V extends SearchTagInputOption>(props: SearchTagInputPro
options,
};
return React.cloneElement(content as JSX.Element, newProps);
}, [selectedOption, options, emptyOption]);
}, [JSON.parse(JSON.stringify(selectedOption)), options, emptyOption]);

return (
<Dropdown
Expand Down
16 changes: 6 additions & 10 deletions packages/react-tag/src/index.tsx
Expand Up @@ -47,19 +47,15 @@ export default (props: TagProps = {}) => {
if (!visible) {
return null;
}
const closeBtn = useMemo(
() =>
closable ? (
<svg onClick={onClose} className={`${prefixCls}-close`} width="15" height="15" viewBox="0 0 16 16">
<path d="M9.41 8l2.29-2.29c.19-.18.3-.43.3-.71a1.003 1.003 0 0 0-1.71-.71L8 6.59l-2.29-2.3a1.003 1.003 0 0 0-1.42 1.42L6.59 8 4.3 10.29c-.19.18-.3.43-.3.71a1.003 1.003 0 0 0 1.71.71L8 9.41l2.29 2.29c.18.19.43.3.71.3a1.003 1.003 0 0 0 .71-1.71L9.41 8z" />
</svg>
) : null,
[closable],
);

return (
<span className={cls} style={styl} {...other}>
{title || children}
{closeBtn}
{closable ? (
<svg onClick={onClose} className={`${prefixCls}-close`} width="15" height="15" viewBox="0 0 16 16">
<path d="M9.41 8l2.29-2.29c.19-.18.3-.43.3-.71a1.003 1.003 0 0 0-1.71-.71L8 6.59l-2.29-2.3a1.003 1.003 0 0 0-1.42 1.42L6.59 8 4.3 10.29c-.19.18-.3.43-.3.71a1.003 1.003 0 0 0 1.71.71L8 9.41l2.29 2.29c.18.19.43.3.71.3a1.003 1.003 0 0 0 .71-1.71L9.41 8z" />
</svg>
) : null}
</span>
);
};

0 comments on commit 61a9651

Please sign in to comment.