From edf7e63fe4de76df8937bf802fa2a1d41ab111fb Mon Sep 17 00:00:00 2001 From: nmccready Date: Mon, 26 Aug 2019 08:45:16 -0400 Subject: [PATCH] ISSUE 4: race old state fix copied from upstream issue 14 --- src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.ts b/src/index.ts index 7971d69..84ba348 100644 --- a/src/index.ts +++ b/src/index.ts @@ -73,8 +73,10 @@ function useCustom( hookWork?: HookWork ): [T, A] { const newListener = React.useState()[1]; + const oldState = this.state; React.useEffect(() => { this.listeners.push(newListener); + if (oldState !== this.state) newListener(this.state); return () => { const listenersLength = this.listeners.length; const filtered = [];