-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Native supports a stable style prop reference with React.memo #3150
Native supports a stable style prop reference with React.memo #3150
Conversation
Hi @philipbulley, thanks for this PR! To be honest, I'd like much more to relaying on the implementation details of React.memo, to detect if the component is memoized or not ( something along the line of |
…or the resulting style prop; Remove styledMemo proposal
@Federkun that's a good point and would be ideal, thanks!
An alternative (also not ideal) is to use introspection on the Element Type Expand for commentary on introspection woes...1️⃣ This would be great, except that it doesn't work, as ReactIs.typeOf(CustomComponent) === ReactIs.Memo
ReactIs.isMemo(CustomComponent) // sugar coated version of above Several people have proposed a solution that can introspect an element type
but neither of these have landed. 2️⃣ This works 🤮 : ReactIs.isMemo(React.createElement(CustomComponent)) // true But I don't imagine it would be at all healthy for perf, especially as this would run for every custom component. Let's not go there! 3️⃣ Another option — if we don't mind looking at implementation details — is this approach: facebook/react/issues/12882#issuecomment-440227651 See the usage of this technique in MobX: I've implemented the technique that MobX uses and it works a treat! I've added tests too. Please see the latest commit.
|
Can anyone who better understands Flow help with this issue please? Why does this happen?
Despite memoize-one having flow types. |
/native
supporting a stable style prop reference
Closing due to inacitivity. I think we could consider changing the approach of dynamic styling in the implementation if we do split off the package to avoid complexity / differences in the CSS pipeline to the main package, see #1617 |
This is a follow up to the closed #3020 (cc: @Federkun, @kitten) and I have raised the following new issue which provides a rationale for the proposed changes: #3149
In #3020, the consensus was that memoization of the resulting style prop would be too expensive to run on every instance when only a subset of use cases would benefit.
Update:
This PR initially explored this approach:
But then after feedback, that was reverted and it now only employs a memoize optimisation for
React.memo
components.Caveats