v1.2.0
Depricate useIsXStateTransitionAvailable()
in favor of the new useStateCan()
. It has the exact same API, but uses state.can(event)
under the hood. Also, it saves you a render when use event objects in by using JSON.stringify(event)
for React.useCallback()
dependencies.
export function useStateCan<
TEventType extends TEvent['type'],
TEvent extends EventObject = EventObject,
>(
service:
| Interpreter<any, any, TEvent, any>
| ActorRef<TEvent>,
event: TEventType | TEvent,
): boolean {
return useSelector<typeof service, boolean>(
service,
useCallback(
state => state.can(event),
// eslint-disable-next-line react-hooks/exhaustive-deps
[service, JSON.stringify(event)],
),
);
}