My question is in the title : How to adjust the size of a textarea automatically according to the text with React
I want to adjust my textarea height dynamically with Refs and pass it to the state but it don't work correctly.
I created a codesandbox to help you to understand what exactly I want.
https://codesandbox.io/s/ol5277rr25
In my example I take the textarea height with Ref and I pass it to the state in the onChange event but for each letter typed the height increases, it don't work correctly..
One other solution would be to split the textarea in an array when line break, and for each line break, increase the textarea height (1 line-break = 1 row). But I can not detect automatic line breaks (for line break when I press Enter no problem).. if you have ideas ?
I have already used react-autosize-textarea but I prefer do that on my own :)