Comments (4)
Hi @philipyoungg, what do you mean by
Currently adding input with controlled component is super slow.
How slow? Do you see a perceptible lag during the input?
Also
It doesn't work.
What have you tried, what doesn't work? Can you show a self-contained example that we can use to reproduce the behavior you're seeing?
from react-autosize-textarea.
Hello @gabro, that's for the speedy follow up! Yes, I experienced perceptible lag during input.
I have tried using ref={node => this.textarea = node}
and innerRef={node => this.textarea = node}
and accessing it with this.textarea.value
. It shows undefined
.
Case: I'm making a to do app with multiple list.
[lists of item]
[controlled textarea input]
On a page with only several todo list, there's no lag whatsoever.
It's become wonky on page with hundreds of lists.
That's why I'm going to uncontrolled route to improve performance.
from react-autosize-textarea.
Hi @philipyoungg and sorry for the delay,
I'm pretty sure your performance issues are caused by useless re-renders that could be avoided, which would explain why you notice that only with a lot of items.
I'll explain myself better: whenever you type I assume you are causing somehow each item of the list to re-render, which is very expensive.
I suggest you to use React.PureComponent
as the default for you components and/or adding a custom shouldComponentUpdate
in your item like this:
let's suppose you have an item with two props: value
and onChange
. We should re-render only if the value
has changed to avoid wasting React's time.
shouldComponentUpdate(nextProps) {
return nextProps.value !== this.props.value;
}
You can read more about this here: https://facebook.github.io/react/docs/optimizing-performance.html#shouldcomponentupdate-in-action
Let me know if this helps you :)
PS: AutosizeTextarea
should probably extend PureComponent
instead of Component
, I'll open a separate issue for that
EDIT: see comment in #64 for a simple implementation that wraps the component with a PureComponent
that automatically adds a tested and official shouldComponentUpdate
as described here: https://facebook.github.io/react/docs/react-api.html#react.purecomponent
from react-autosize-textarea.
I'm closing this for now, if anyone still has perf problems feel free to comment here :)
from react-autosize-textarea.
Related Issues (20)
- autoFocus doesn't work HOT 1
- IE11 not supported (?) HOT 1
- Passing a function to ref fails prop type validation HOT 6
- THANK YOU! HOT 1
- lose ref value after rerendering page HOT 3
- Switch to forwardRef instead of callback style ref HOT 1
- Function passed to innerRef is never called HOT 1
- onChange typescript definition problem HOT 1
- How the initial height of the textarea is calculated ? HOT 1
- Failed prop type: Invalid prop `innerRef` of type `function` supplied to `TextareaAutosizeClass`, expected `object` HOT 3
- Styled Component example seems to be broken HOT 2
- How to ADD EMOJI PICKER??
- 7.1 version breaks TypeScript projects by declaring optional properties as required HOT 5
- How to 'force' auto-height calculation? HOT 1
- Add react 17 as peer dependency HOT 5
- "Paste" doesn't work HOT 1
- Bottom padding missing in Firefox HOT 1
- Bug with latest version of autosize HOT 3
- Using StyledComponents and MaxRows without "jumps"
- Page scrolls up when typing (when being zoomed out in Safari) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-autosize-textarea.