From 828e734fc79affeef1aa3ca74aca723e2856d67d Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Fri, 26 Nov 2021 08:52:00 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20Example=20-=20Update=20`ContextM?= =?UTF-8?q?enuViewTest08`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/examples/ContextMenuViewTest08.tsx | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/example/src/examples/ContextMenuViewTest08.tsx b/example/src/examples/ContextMenuViewTest08.tsx index 78cef7e..3955f4f 100644 --- a/example/src/examples/ContextMenuViewTest08.tsx +++ b/example/src/examples/ContextMenuViewTest08.tsx @@ -20,24 +20,6 @@ export function ContextMenuViewTest08(props: ContextMenuExampleProps) { }; }, []); - const startTimer = () => { - intervalRef.current = setInterval(() => { - if (counter < 3){ - setCounter(prevValue => (prevValue + 1)); - - } else { - menuRef.current.dismissMenu(); - }; - }, 500); - }; - - const resetTimer = () => { - if(this.timer){ - clearInterval(intervalRef.current); - setCounter(0); - }; - }; - return ( ( - {`Will Dismiss in: ${3 - this.state.counter}`} + {`Will Dismiss in: ${3 - counter}`} )} - onMenuDidShow={startTimer} - onMenuDidHide={resetTimer} + onMenuDidShow={() => { + let internalCounter = 0; + + intervalRef.current = setInterval(() => { + if (internalCounter < 3){ + setCounter(prevValue => (prevValue + 1)); + internalCounter++; + + } else if(internalCounter === 3) { + menuRef.current.dismissMenu(); + }; + }, 500); + }} + onMenuDidHide={() => { + clearInterval(intervalRef.current); + setCounter(0); + }} >