Skip to content
Advertisement

TextInput gets unfocused after typing each character

I’m using React to build a form and I’m trying to filter a list with the SearchInput (which works the same as TextInput) located in the child component Header. But everytime I type a character the SearchInput gets unfocused

JavaScript

Advertisement

Answer

Oh, I think I can see the problem now – it’s the way you’re rendering the <SearchInput /> component. You’re inadvertantly creating a new functional component on every render. Either inline the Header directly into the Parent control’s headerContent property, or create an entirely separate component:

JavaScript

While you’re there, you have a subtle bug with your comparison – it looks like you’re searching your partners effectively as a list of strings; but, since you’re joining them, if you had partners with the names:

JavaScript

You’re creating a search string as ‘onetwo’ – so searching for ‘et’ would match, even though you don’t actually have a partner matching that. You can fix that by just checking each partner individually… something like:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement