UNPKG

@foreverrbum/ethsign

Version:

This package will allow you to electronically sign documents within your application

22 lines (18 loc) 570 B
import React, { useState, useRef, useEffect } from 'react'; export const AutoResizeInput = (props) => { const [content, setContent] = useState(props.value); const [width, setWidth] = useState(0); const span = useRef(); useEffect(() => { setWidth(span.current.offsetWidth); }, [content]); useEffect(() => { setContent(props.value); }, [props.value]) return ( <wrapper> <input type="text" style={{ width }} {...props} /> <span className="absolute opacity-0 px-1 whitespace-pre" ref={span}>{content}</span> </wrapper> ); };