Skip to content

Commit

Permalink
fix: deactivation sequence, fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Oct 1, 2019
1 parent dae9a1c commit 32ed7d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions example/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export default class App extends Component <{}, AppState> {
onClickOutside={toggle}
onEscapeKey={toggle}
shards={[this.toggleRef, this.scrollRef]}
onActivation={() => console.log("activated")}
onDeactivation={() => console.log("deactivated")}
>
Holala!!
<button onClick={()=>alert('ok')}>test inside event</button>
Expand Down
11 changes: 6 additions & 5 deletions src/Effect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function Effect(
onDeactivation,
noIsolation
}: EffectProps) {
const [activeNode, setActive] = useState<HTMLElement | null>(null);
const [activeNode, setActive] = useState<HTMLElement | null | undefined>(undefined);

const lastEventTarget = useRef<EventTarget>(null);

Expand Down Expand Up @@ -71,12 +71,13 @@ export function Effect(
if (onActivation) {
onActivation(activeNode);
}
} else {
if (onDeactivation) {
onDeactivation();
return () => {
if (onDeactivation) {
onDeactivation();
}
}
}
}, [activeNode]);
}, [!!activeNode]);

This comment has been minimized.

Copy link
@benoitgrelard

benoitgrelard Oct 1, 2019

Contributor

nice idea!


useEffect(() => {
let _undo = (): any => null;
Expand Down

0 comments on commit 32ed7d7

Please sign in to comment.