Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

550 B
Raw Blame
import { useEffect, useState } from 'react'

export function useChartOptionTextDraft(
    value: string | undefined,
    onChange: (value: string | undefined) => void
): { draft: string; setDraft: (draft: string) => void; commit: () => void } {
    const [draft, setDraft] = useState(value ?? '')

    useEffect(() => {
        setDraft(value ?? '')
    }, [value])

    const commit = (): void => {
        const trimmed = draft.trim()
        setDraft(trimmed)
        onChange(trimmed || undefined)
    }

    return { draft, setDraft, commit }
}