mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
fix multiselect trigger onOpen/onClose after first render
This commit is contained in:
parent
2ec1448841
commit
eed4a63243
1 changed files with 18 additions and 13 deletions
|
|
@ -41,22 +41,27 @@ const Multiselect = ({ className, direction, title, options, selected, disabled,
|
|||
closeMenu();
|
||||
}
|
||||
}, [dataset, onSelect]);
|
||||
const mountedRef = React.useRef(false);
|
||||
React.useLayoutEffect(() => {
|
||||
if (menuOpen) {
|
||||
if (typeof onOpen === 'function') {
|
||||
onOpen({
|
||||
type: 'open',
|
||||
dataset: dataset
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (typeof onClose === 'function') {
|
||||
onClose({
|
||||
type: 'close',
|
||||
dataset: dataset
|
||||
});
|
||||
if (mountedRef.current) {
|
||||
if (menuOpen) {
|
||||
if (typeof onOpen === 'function') {
|
||||
onOpen({
|
||||
type: 'open',
|
||||
dataset: dataset
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (typeof onClose === 'function') {
|
||||
onClose({
|
||||
type: 'close',
|
||||
dataset: dataset
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mountedRef.current = true;
|
||||
}, [menuOpen]);
|
||||
return (
|
||||
<Popup
|
||||
|
|
|
|||
Loading…
Reference in a new issue