I'm working on an app that has a reusable component that generates text areas when needed. This component receives an onChange function as a prop from its parent with the prop name onChange. The existing code uses a textarea element that has a consistent height, and this textarea triggers the onChange function without issue.
I am now working on getting the area to grow vertically instead of adding an overflow bar, and have replaced the textarea tag with a div, which allows the autogrowth to work as expected. However, the div tag will no longer trigger the onChange prop that the textarea element triggered without issue. I'm able to confirm that the onChange prop carries the same function over, but I'm stumped as to why it won't work. I was wondering if there is something that I'm missing in my code, or if I'm misunderstanding about how onChange functions work within React. I've pasted the original code and my best guess at what the updated code should look like, although I've tried multiple changes on the div.
Thanks in advance for any help on this!
Original textarea code:
<textarea className={textAreaStyle} {...textareaProps} rows={rows} />
Updated div code:
<div
className={textAreaStyle}
rows={rows}
contentEditable="true"
{...textareaProps}
onChange={props.onChange}
>
{value}
</div>
Update 1: I've tried replacing the line onChange={props.onChange}
with onInput={props.onChange}
, and now the function is being hit, but the actual state isn't being updated. Seeing if I can fix the state not being updated to resolve this issue.