I am trying to get the width of a ref (to a styled textarea element), and I am trying to get it every time that I add text to it:
const Input = styled.textarea`
min-height: 44px;
max-width: 50px;
margin-right: 15px;
padding: 12px 22px;
font-size: 14px;
`;
class App extends Component {
state = { textArea: "" };
handleChange = e => {console.log("this.textAreaRef.offsetWidth",
this.textAreaRef.offsetWidth);
this.setState({
textArea: e.target.value
});
};
render() {
const { textArea } = this.state;
return (
<Input
ref={textAreaRef => {
this.textAreaRef = textAreaRef;
}}
onChange={this.handleChange}
value={textArea}
/>
);
}
}
I am able to get a width value console logged, but my problem is that it does not change as I add more text to it.
Here it is on codesandbox: https://codesandbox.io/s/vqk4kk8503