Description When a TextInput component triggers action such as in onChangeText or onKeyPress method which then triggers setState, the component will re render and lose focuse.
React Native version: 0.62 (Unable to upgrade due to use of Expo)
Steps To Reproduce Provide a detailed list of steps that reproduce the issue.
Expected Results sets State but does not lose focus or rerenders
Snack, code example, screenshot, or link to a repository: Expo Example https://snack.expo.io/@ksi9302/1f9369
Hi Guys, this is a bug report I made to React Native. But I'm not sure if I'm doing something wrong here.
What I've tried so far and doesn't work
What I know will work
Bad Compromise
Take the wrapper out as it keeps getting rerendered due to the search value changes.
import React, { useState } from "react";
import { View, TextInput } from "react-native";
const Test = () => {
const handleChange = e => {
setSearch(e);
};
const [search, setSearch] = useState(null);
return (
<Wrapper>
<TextInput
value={search}
onChangeText={e => {
handleChange(e);
}}
placeholder="type here"
/>
</Wrapper>
);
};
const Wrapper = props => {
return (
<View
style={{
width: "100%",
height: "100%",
alignItems: "center",
justifyContent: "center",
display: "flex",
}}
>
{props.children}
</View>
);
};
export default Test;