import { useEffect, useRef, useState } from "react"; import "./style.css"; interface IWidget { defaultValue?: string; value?: string; placeholder?: string; style?: React.CSSProperties; onChange?: Function; onKeyDown?: Function; onBlur?: Function; onPressEnter?: Function; } const EditableLabelWidget = ({ defaultValue, value, placeholder, style, onChange, onKeyDown, onBlur, onPressEnter, }: IWidget) => { const [textAreaValue, setTextAreaValue] = useState(defaultValue); const [shadowText, setShadowText] = useState(defaultValue); const [textAreaHeight, setTextAreaHeight] = useState(31); const [shadowHeight, _setShadowHeight] = useState(31); const refTextArea = useRef(null); const refShadow = useRef(null); useEffect(() => { setTextAreaValue(value); setShadowText(value); }, [value]); useEffect(() => { setTextAreaHeight(refShadow.current?.clientHeight); }, []); return (
) => { setTextAreaHeight(refShadow.current?.clientHeight); }} > {shadowText}