Skip to content

Commit

Permalink
fix(overmind-react): fix production
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed Aug 8, 2020
1 parent 7e3dac0 commit 8efeff7
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions packages/node_modules/overmind-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,33 @@ const useState = <Config extends IConfiguration>(): Overmind<Config>['state'] =
}

if (IS_PRODUCTION) {
react.useEffect(
() => () => {
;(overmind as any).proxyStateTree.disposeTree(trackingRef.current.tree)
},
[]
)
react.useLayoutEffect(() => {
trackingRef.current.mounted = true


react.useLayoutEffect(() => trackingRef.current.tree.stopTracking())
if (trackingRef.current.hasUpdatedBeforeCommit) {
forceRerender()
}

trackingRef.current.tree.track(forceRerender)
return () => {
;(overmind as any).proxyStateTree.disposeTree(trackingRef.current.tree)
}
}, [])

react.useLayoutEffect(() => {
if (trackingRef.current.stopTrackingTask) {
unstable_cancelCallback(trackingRef.current.stopTrackingTask)
trackingRef.current.stopTrackingTask = null
}
trackingRef.current.tree.stopTracking()
})
trackingRef.current.tree.track(() => {
if (trackingRef.current.mounted) {
forceRerender()
} else {
trackingRef.current.hasUpdatedBeforeCommit = true
}
})
} else {
const component = useCurrentComponent()
const name = component.name
Expand Down

0 comments on commit 8efeff7

Please sign in to comment.