-
Notifications
You must be signed in to change notification settings - Fork 4k
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
RFC: Use PureComponent #1020
Comments
I don't think we should implement this, here's why: Quoting
Almost all of our components can render JSX children, meaning, someone's app can potentially be shallow comparing all our components for no reason. Quoting Abramov from facebook/react#7195 (comment):
Quoting Abramov again, from
Finally, per the PureComponent docs:
Note, the distinction of "some cases" in the performance boost comment. Moreover, consider the warning that follows. ConclusionIf we did add PureComponent, it would probably only be to the Even if we could add this feature we have no way of ensuring that child components are pure since users are free to use any child components they wish inside ours. We should likely leave this implementation to apps that integrate our lib rather than implementing it ourselves. |
This is due to your top level component being connected. For maximum performance, you can connect each form control individually. This way, when your data changes, only the form controls that are connected to that data update.
I would say yes. However, this is a Redux performance pattern and not specific to Semantic UI React. |
@levithomason I have not seen any further discussion about these two components being converted to |
The icon perf issues are a known issue and not related to PureComponent but to #1184. In short, the propType validator is very expensive and needs memoized. I would still be up for using PureComponent in Icon and Flag except that it is only available for React 15.3 (released on June 29, 2016). There may be users on older versions of React. However, we could simply add PR for manually implementing |
Hate to open an old issue, BUT is there a workaround or best practice in the event I want to use something like PureComponent with Semantic? We have 20 renderings of a Card component, and several subcomponents, and if a user clicks a textbox, it all rerenders, locks the screen and takes 3-4 seconds before they can type. Narrowed it down to the Card component... My parent components are using PureComponent but it appears to not care much about that.... |
Wrap your components with React.memo: https://reactjs.org/docs/react-api.html#reactmemo |
Hello, guys!
PureComponent
I want to speak about next optimization topic -
PureComponent
. It's previously known as pure render mixin, it makes shallow compare of props insideshouldComponentUpdate()
. Inheriting fromReact.PureComponent
indicates to React that your component doesn't need to rerender when the props are unchanged (#7195).I'm using it in my app and it's perfect 😸 There are some benchmarks and conclusions.
Benefits
We will loose stateless components, according to Dan Abramov they are same as statefull inside, so the same slow as
Component
child. Also, now we have stateless, statefull and statefull component without real state (#607), after refactoring we will haveComponent
andPureComponent
classes 👍Limitations
@jcarbo @levithomason thoughts?
The text was updated successfully, but these errors were encountered: