-
Notifications
You must be signed in to change notification settings - Fork 704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I make it work with react hooks #383
Comments
@utiq You need to get the current value from the ref import React, {
useRef,
useState,
useEffect
} from 'react'
import autosize from 'autosize'
const TextboxCounter = ({ ...rest }) => {
const textareaRef = useRef()
useEffect(() => {
// .current holds dom element
autosize(textareaRef.current)
}, [])
return (
<div>
<textarea {...rest} ref={textareaRef} placeholder="Enter your comment here"></textarea>
<p>Characters Left: {charsLeft}</p>
</div>
)
}
export default TextboxCounter |
This works, but creates a "jumpy" experience in Chrome on OS X. You can see the textarea initializing with a default height, and then "jumping" to it's autosized height. Any ideas how to fix that? |
I created a component using this library https://github.com/albertcito/texarea-autosize-reactjs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to make it work with functional components and hooks, but it doesn't work, what I'm doing wrong?
The text was updated successfully, but these errors were encountered: