Skip to content

Commit ef21a65

Browse files
fix(overmind-react): fix bad refactor
1 parent 553b093 commit ef21a65

File tree

1 file changed

+10
-13
lines changed
  • packages/node_modules/overmind-react/src

1 file changed

+10
-13
lines changed

packages/node_modules/overmind-react/src/index.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ export const createHook = <Config extends IConfiguration>(
7474
? ReactCurrentOwner.current.elementType
7575
: {}
7676
}
77-
const useForceRerender = (cb?: () => void) => {
78-
const [, setState] = useState(() => {
79-
cb && cb()
80-
return true
81-
})
77+
const useForceRerender = () => {
78+
const [, setState] = useState(() => true)
8279
const forceRerender = (_, __, flushId): void => {
8380
setState(flushId)
8481
}
@@ -128,14 +125,7 @@ export const createHook = <Config extends IConfiguration>(
128125
currentComponentInstanceId++
129126
)
130127

131-
const rerenderComponent = useForceRerender(() => {
132-
overmind.eventHub.emitAsync(EventType.COMPONENT_ADD, {
133-
componentId: component.__componentId,
134-
componentInstanceId,
135-
name,
136-
paths: Array.from(tree.pathDependencies) as any,
137-
})
138-
})
128+
const rerenderComponent = useForceRerender()
139129

140130
tree.track((_, __, flushId) => {
141131
rerenderComponent(_, __, flushId)
@@ -151,6 +141,13 @@ export const createHook = <Config extends IConfiguration>(
151141
useLayoutEffect(() => tree.stopTracking())
152142

153143
useEffect(() => {
144+
overmind.eventHub.emitAsync(EventType.COMPONENT_ADD, {
145+
componentId: component.__componentId,
146+
componentInstanceId,
147+
name,
148+
paths: Array.from(tree.pathDependencies) as any,
149+
})
150+
154151
return () => {
155152
;(overmind as any).proxyStateTree.disposeTree(tree)
156153
overmind.eventHub.emitAsync(EventType.COMPONENT_REMOVE, {

0 commit comments

Comments
 (0)