question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using styled API causes children Inputs to lose focus (May be from re-renders)

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
nandorojocommented, Sep 27, 2020

Not sure how I didn’t think of this sooner. I can move the pure function logic for the sx prop directly into createThemedComponent. This way, the styled component will do zero magic — it will just be for nicer syntax. Besides figuring out the TS suggestions, this should be easy.

0reactions
nandorojocommented, Sep 28, 2020

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 since styled is going to get rid of that implementation anyway in favor of putting a pure function option for defaultStyle in createThemedComponent, I’ll close this for now.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found