I have this strange issue, keyboard keeps closing while typing when TextInput is placed inside Child Functional Component. This issue does not exist if TextInput is placed d
your SignInForm
function (which is treated like React component, because its capitalized and called as JSX) is declared inside your SignInScreenC
component. This means that every render, new type of React component is created.
SignInScreenC
renders first time: creates SignInForm
component, instantiates it and renders itSignInScreenC
renders second time: creates another, completely different SignInForm
component, instantiates it again, effectively unmounting old SignInForm
and rendering new SignInForm
in it's placeThis is due to the way React handles rendering: whenever it encounters different type of element that should be rendered in place of an old element, old one will be unmounted. To react, every new SignInForm
is different from the previous one as you keep constantly creating new functions
Solutions:
SignInForm
component outside of SignInScreenC
and pass all the necessary data as propsconst SignInForm = () => return (...)
use const renderSignInForm = () => return (...)
, and while rendering, instead of <SignInForm/>
call it like {renderSignInForm()}
. This way it will not be treated like a component and will not be a subject to unmounts