diff --git a/examples/navigation/src/settings/Settings.tsx b/examples/navigation/src/settings/Settings.tsx
index d5eefab..c23524d 100644
--- a/examples/navigation/src/settings/Settings.tsx
+++ b/examples/navigation/src/settings/Settings.tsx
@@ -4,7 +4,7 @@ import React from "react";
import SettingsViewModel from "./settingsViewModel";
export function Settings() {
- const vm = useViewModel(() => new SettingsViewModel(), {}, []);
+ const { vm } = useViewModel(() => new SettingsViewModel(), {}, []);
return (
diff --git a/packages/views/src/hooks/useViewModel.ts b/packages/views/src/hooks/useViewModel.ts
index 988cc23..7126f2a 100644
--- a/packages/views/src/hooks/useViewModel.ts
+++ b/packages/views/src/hooks/useViewModel.ts
@@ -1,10 +1,9 @@
"use client";
import type { DependencyList } from "react";
-import { useEffect, useRef } from "react";
+import { useEffect, useRef, useState } from "react";
import { ViewModelLifecycleManager } from "../helpers/viewModelLifecycleManager";
import type { IViewModel } from "../types";
-import { ManualPromise } from "@frui.ts/helpers";
export function useViewModel>(
factory: () => TViewModel,
@@ -12,15 +11,13 @@ export function useViewModel>(
dependencies?: DependencyList
) {
const vmManager = useRef(new ViewModelLifecycleManager(factory));
- const initializedPromise = useRef(new ManualPromise());
+ const [initialized, setInitialized] = useState(false);
const currentContext = useRef(context);
currentContext.current = context;
useEffect(() => {
- void vmManager.current
- .initialize(currentContext.current)
- .then(() => initializedPromise.current.status === "new" && initializedPromise.current.resolve(true));
+ void vmManager.current.initialize(currentContext.current).then(() => setInitialized(true));
return () => {
void vmManager.current.close(currentContext.current);
@@ -31,5 +28,5 @@ export function useViewModel>(
void vmManager.current.navigate(currentContext.current);
}, dependencies ?? [context]);
- return { vm: vmManager.current.instance, initialized: initializedPromise.current.promise };
+ return { vm: vmManager.current.instance, initialized };
}
diff --git a/stories/package.json b/stories/package.json
index 51977c3..abcfaf9 100644
--- a/stories/package.json
+++ b/stories/package.json
@@ -27,7 +27,7 @@
"react": "^18.2.0"
},
"scripts": {
- "storybook": "cross-env NODE_OPTIONS=--openssl-legacy-provider storybook dev -p 6006",
- "build-storybook": "cross-env NODE_OPTIONS=--openssl-legacy-provider storybook build"
+ "storybook": "storybook dev -p 6006",
+ "build-storybook": "storybook build"
}
}