'use client'; import React, { useState, useEffect, useServerInsertedHTML, useSyncExternalStore } from 'react'; import { getRegisteredCss, subscribeRegisteredCss } from 'typestyles/server'; /** * Subscribe to typestyles CSS changes. Use this in client components * that need to stay up-to-date with dynamically registered styles. * Re-renders whenever new CSS rules are registered on the client. * * @example * ```tsx * // components/Styles.tsx * 'use client'; * import { useTypestyles } from '@typestyles/next/client'; * * export function Styles() { * useTypestyles(); * return null; * } * ``` */ export function useTypestyles() { return useSyncExternalStore( subscribeRegisteredCss, () => getRegisteredCss(), () => getRegisteredCss(), ); } /** * Collect styles during server rendering for App Router. * Use this in a Client Component wrapper that collects styles from its children. * * @example * ```tsx * // components/TypestylesProvider.tsx * 'use client'; * * import { useServerInsertedHTML, getRegisteredCss } from '@typestyles/next/client'; * * export function TypestylesProvider({ children }: { children: React.ReactNode }) { * useServerInsertedHTML(() => { * return ( *