Using styled API causes children Inputs to lose focus (May be from re-renders)
See original GitHub issueDescription
When using the styled API inputs lose focus preventing the user from typing.
This does not however happen with the createThemeComponent API.
Notes
I’m currently using Formik to handle forms with React Native. I’m not sure of the impact of this on the bug.
Example
Causes inputs to lose focus:
const Card = styled(View, {
themeKey: "cards",
defaultVariant: "primary",
})({});
Doesn’t cause inputs to lose focus:
const Card = createThemedComponent(View, {
themeKey: "cards",
defaultVariant: "primary",
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
React.js - input losing focus when rerendering - Stack Overflow
The loss of focus happens because the component prop uses React.createElement each time instead of just re-rendering the changes. Details here: https:// ...
Read more >Input losing focus after every character written #730 - GitHub
It causes its child Fields and inputs to lose focus. inputs ... <form> does not rerender after every keystroke, inputs stay focused.
Read more >React.js loses input focus on typing
I recently stumbled upon an interesting problem. React.js was loosing focus on an input while the user was typing. Here is a video...
Read more >Using `React.memo` to Avoid Unnecessary Rerenders
We can use the top level `React.memo` API to avoid unnecessary rerenders of our function components in a React app. In this post ......
Read more >React Text Input Losing Focus After Each Keypress
I had a simple text input on a form. And if you typed, say an 'r' into the text input, it would display...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Not sure how I didn’t think of this sooner. I can move the pure function logic for the
sxprop directly intocreateThemedComponent. This way, thestyledcomponent will do zero magic — it will just be for nicer syntax. Besides figuring out the TS suggestions, this should be easy.Okay cool. Seems like the previous implementation of
styled, which forwarded refs twice, was the cause. Since there’s a bug for that in RNW, and sincestyledis going to get rid of that implementation anyway in favor of putting a pure function option fordefaultStyleincreateThemedComponent, I’ll close this for now.