useSpawn.js 646 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.useSpawn = void 0;
  4. var xstate_1 = require("xstate");
  5. var useConstant_1 = require("./useConstant");
  6. /**
  7. * React hook that spawns an `ActorRef` with the specified `behavior`.
  8. * The returned `ActorRef` can be used with the `useActor(actorRef)` hook.
  9. *
  10. * @param behavior The actor behavior to spawn
  11. * @returns An ActorRef with the specified `behavior`
  12. */
  13. function useSpawn(behavior) {
  14. var actorRef = (0, useConstant_1.default)(function () {
  15. return (0, xstate_1.spawnBehavior)(behavior);
  16. });
  17. return actorRef;
  18. }
  19. exports.useSpawn = useSpawn;