@zag-js/react
Advanced tools
Comparing version 0.0.0-dev-20240714222614 to 0.0.0-dev-20240723090825
@@ -98,2 +98,5 @@ "use client" | ||
// ../../utilities/core/src/guard.ts | ||
var isDev = () => process.env.NODE_ENV !== "production"; | ||
// ../../utilities/core/src/object.ts | ||
@@ -195,2 +198,5 @@ function compact(obj) { | ||
// src/use-service.ts | ||
var import_react6 = require("react"); | ||
// src/use-constant.ts | ||
@@ -217,5 +223,10 @@ var import_react4 = require("react"); | ||
}); | ||
const snapshotRef = (0, import_react6.useRef)(); | ||
useSafeLayoutEffect(() => { | ||
service.start(hydratedState); | ||
const stateInit = hydratedState ?? snapshotRef.current; | ||
service.start(stateInit); | ||
return () => { | ||
if (isDev()) { | ||
snapshotRef.current = service.getHydrationState(); | ||
} | ||
service.stop(); | ||
@@ -222,0 +233,0 @@ }; |
{ | ||
"name": "@zag-js/react", | ||
"version": "0.0.0-dev-20240714222614", | ||
"version": "0.0.0-dev-20240723090825", | ||
"description": "The react wrapper for zag", | ||
@@ -30,5 +30,5 @@ "keywords": [ | ||
"proxy-compare": "3.0.0", | ||
"@zag-js/core": "0.0.0-dev-20240714222614", | ||
"@zag-js/store": "0.0.0-dev-20240714222614", | ||
"@zag-js/types": "0.0.0-dev-20240714222614" | ||
"@zag-js/core": "0.0.0-dev-20240723090825", | ||
"@zag-js/store": "0.0.0-dev-20240723090825", | ||
"@zag-js/types": "0.0.0-dev-20240723090825" | ||
}, | ||
@@ -41,3 +41,3 @@ "devDependencies": { | ||
"clean-package": "2.2.0", | ||
"@zag-js/utils": "0.0.0-dev-20240714222614" | ||
"@zag-js/utils": "0.0.0-dev-20240723090825" | ||
}, | ||
@@ -44,0 +44,0 @@ "peerDependencies": { |
import type { MachineSrc, StateMachine as S } from "@zag-js/core" | ||
import { useRef } from "react" | ||
import { useConstant } from "./use-constant" | ||
import { useSafeLayoutEffect } from "./use-layout-effect" | ||
import { isDev } from "@zag-js/utils" | ||
@@ -19,5 +21,12 @@ export function useService< | ||
const snapshotRef = useRef<S.StateInit<TContext, TState>>() | ||
useSafeLayoutEffect(() => { | ||
service.start(hydratedState) | ||
const stateInit = hydratedState ?? snapshotRef.current | ||
service.start(stateInit) | ||
return () => { | ||
// HMR improvements for dev | ||
if (isDev()) { | ||
snapshotRef.current = service.getHydrationState() | ||
} | ||
service.stop() | ||
@@ -24,0 +33,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61230
641
3
+ Added@zag-js/core@0.0.0-dev-20240723090825(transitive)
+ Added@zag-js/store@0.0.0-dev-20240723090825(transitive)
+ Added@zag-js/types@0.0.0-dev-20240723090825(transitive)
- Removed@zag-js/core@0.0.0-dev-20240714222614(transitive)
- Removed@zag-js/store@0.0.0-dev-20240714222614(transitive)
- Removed@zag-js/types@0.0.0-dev-20240714222614(transitive)