mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 21:15:18 +09:00
Similar to react-sdk/runtime added another entry point to sdk package which includes all the stuff imported on published sites to reduce js size. ./fixtures/webstudio-remix-netlify-functions/build/client: 392kB (-176kB)
19 lines
482 B
TypeScript
19 lines
482 B
TypeScript
import { useState, useMemo, type Dispatch, type SetStateAction } from "react";
|
|
import {
|
|
createJsonStringifyProxy,
|
|
isPlainObject,
|
|
} from "@webstudio-is/sdk/runtime";
|
|
|
|
export const useVariableState = <S,>(
|
|
initialState: S | (() => S)
|
|
): [S, Dispatch<SetStateAction<S>>] => {
|
|
const [state, setState] = useState(initialState);
|
|
|
|
const value = useMemo(
|
|
() => (isPlainObject(state) ? createJsonStringifyProxy(state) : state),
|
|
[state]
|
|
);
|
|
|
|
return [value, setState];
|
|
};
|