I'm trying to change the size of a textarea with the text. The code is working but for any reason that I don't get, the textarea resizes with the first letter I stroke and then works propertly. Any idea what is causing this weird first resizing?
This is the code I have in the app.js in a recently created project.
import './App.css';
function App() {
function handleKeyDown(e) {
e.target.style.height = 'inherit';
e.target.style.height = `${e.target.scrollHeight}px`;
}
return (
<div>
<header className="App-header" style={{
display: 'flex',
justifyContent: 'center',
width: '470px',
backgroundColor: '#fff',
borderRadius: '5px',
padding: '25px 25px 30px'
}} >
<div>
<textarea onChange={handleKeyDown} style={{
width: '95%',
padding: '15px',
borderRadius: '5px',
outline: 'none',
resize: 'none'
}} />
</div>
</header>
</div>)
;}
export default App;
Any idea what is causing this weird first resizing? Maybe there is something I'm missing, any clue can help.
Thanks.