@@ -80,18 +80,24 @@ export function useMachine<T extends BaseSchema>(
8080
8181 let previousEventRef : any = { current : null }
8282 let eventRef = { current : { type : "__init__" } }
83- const currentEvent = ( ) => eventRef . current
84- const previousEvent = ( ) => previousEventRef . current
83+
84+ const getEvent = ( ) => ( {
85+ ...eventRef . current ,
86+ current ( ) {
87+ return eventRef . current
88+ } ,
89+ previous ( ) {
90+ return previousEventRef . current
91+ } ,
92+ } )
8593
8694 const refs = useRefs ( machine . refs ?.( { prop, context : ctx } ) ?? { } )
8795
8896 const getParams = ( ) : any => ( {
8997 state,
9098 context : ctx ,
91- event : {
92- ...eventRef ,
93- current : currentEvent ,
94- previous : previousEvent ,
99+ get event ( ) {
100+ return getEvent ( )
95101 } ,
96102 prop,
97103 send,
@@ -150,7 +156,9 @@ export function useMachine<T extends BaseSchema>(
150156 return (
151157 machine . computed ?. [ key ] ( {
152158 context : ctx as any ,
153- event : eventRef . current ,
159+ get event ( ) {
160+ return getEvent ( )
161+ } ,
154162 prop,
155163 refs,
156164 get scope ( ) {
@@ -216,8 +224,8 @@ export function useMachine<T extends BaseSchema>(
216224 }
217225
218226 const send = ( event : any ) => {
219- previousEventRef = eventRef
220- eventRef = event
227+ previousEventRef . current = eventRef . current
228+ eventRef . current = event
221229
222230 let currentState = getCurrentState ( )
223231
@@ -263,10 +271,8 @@ export function useMachine<T extends BaseSchema>(
263271 scope : scope . value ,
264272 refs,
265273 computed,
266- event : {
267- ...eventRef ,
268- current : currentEvent ,
269- previous : previousEvent ,
274+ get event ( ) {
275+ return getEvent ( )
270276 } ,
271277 } as Service < T >
272278}
0 commit comments