React Native TextInput Value persist when Tab is changed

I have encountered a weird issue in the newest react native where the value in the text input in a component remains when a tab is switched.

I can’t figure what is going on and I thought it should re-render when tab is changed but it doesn’t.

Here’s my code
app.js

export default function App() {
  const [tab, setTab] = useState("TAB1")
  return (
    <View style={styles.container}>
      <View style={{ flexDirection: 'row' }}>
        <TouchableOpacity
          style={{ borderRadius: 5, borderWidth: 1, marginRight: 5, padding: 20 }}
          onPress={() => setTab("TAB1")}
        >
          <Text>Tab 1</Text>
        </TouchableOpacity>
        <TouchableOpacity
          style={{ borderRadius: 5, borderWidth: 1, padding: 20}}
          onPress={() => setTab("TAB2")}
        >
          <Text>Tab 2</Text>
        </TouchableOpacity>
      </View>
      <View style={{ marginTop: 20}}>
        {
          tab === "TAB1" ? (
            <View>
              <InputComponent tab={tab} />
            </View>
          ) : (
              <View>
                <InputComponent tab={tab} />
              </View>
            )
        }
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    marginTop: 100,
    padding: 10
  },
});

inputcomponent.js

export function InputComponent({ tab }) {
    const [value, setValue] = useState("");

    return (
        <View>
            <Text>{tab}</Text>
            <TextInput placeholder="INPUT HERE"  value={value} onChangeText={setValue}/>
        </View>
    )
}

It seems like the input component re-renders but the text input within it doesn’t change.

Demo Issue

31 thoughts on “React Native TextInput Value persist when Tab is changed”

  1. pharmacie lafayette gambetta quai victor hugo narbonne pharmacie auchan gien , pharmacie de garde aujourd’hui 68 pharmacie avignon republique , Lasilix livraison QuГ©bec, Lasilix livraison QuГ©bec. Lasilix sans ordonnance QuГ©bec Lasilix pas cher [url=https://troublesrwma.asso-web.com/#]Lasilix livraison QuГ©bec[/url] pharmacie amiens hopital nord Paroxetine prix sans ordonnance, Acheter Paroxetine comprimГ© pas cher. Paroxetine sans ordonnance Canada Paroxetine pas cher [url=https://doc48prov.asso-web.com/#]Paroxetine livraison Canada, Paroxetine prix sans ordonnance[/url] , pharmacie royale annecy pharmacie leclerc libourne , pharmacie en ligne xenical. pharmacie de garde marseille ce soir Finasteride livraison Luxembourg, Acheter Finasteride 1 mg pas cher. Finasteride sans ordonnance Luxembourg Finasteride pas cher [url=https://truegosa.asso-web.com/#]Finasteride livraison Luxembourg[/url] , pharmacie leclerc kergaradec pharmacie leclerc etampes, pharmacie la garenne argenteuil traitement thermique . pharmacie auchan taverny, pharmacie urgence brest therapies comportementales et cognitives angers pharmacie de garde elbeuf .

    Reply