Skip to content

v1.2.0

Compare
Choose a tag to compare
@VanTanev VanTanev released this 11 Nov 17:07
· 4 commits to development since this release

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)],
    ),
  );
}