¿Cómo puedo agregar una entrada de texto en React Native con solo hacer clic en un botón? Por ejemplo, presionaría el botón "+" y agregaría una entrada de texto en la parte inferior de la Vista.
aquí está el código que encontré en otra página, pero cuando hago clic en el signo más, no pasa nada
var textInput = [] let addTextInput = (key) => { textInput.push(<TextInput key={key} style={{color:'red',borderColor:'red'}}/>); { textInput } } let orgServiceandWorkHours = ( <View> <Button title='+' onPress={() => addTextInput(textInput.length)} /> {textInput.map((value, index) => { return value })} </View> )Aquí hay un ejemplo completo ( https://snack.expo.dev/@heytony01/mature-carrot ) y el código a continuación.
export default function App() { const [numTextInputs,setNumTextInputs] = React.useState(0); return ( <View style={styles.parent}> {/* Button */} <TouchableOpacity onPress={()=>setNumTextInputs(val=>val+1)} style={styles.buttton}> <Text style={styles.text}> Add TextInput </Text> </TouchableOpacity> <ScrollView style={{flex:1}} > {[...Array(numTextInputs).keys()].map(key=>{ return <TextInput key={key} placeholder="Here Man" style={{width:200,height:100,borderColor:"blue",margin:10,borderWidth:1}}/> })} </ScrollView> </View> ); } const styles = StyleSheet.create({ parent:{flex:1,justifyContent:"center",alignItems:"center"}, textInput:{width:"80%",height:"5%",backgroundColor:"lightgray",margin:20,borderRadius:10,textAlign:"center"}, buttton:{width:"80%",height:"12%",backgroundColor:"lightblue",borderRadius:10, justifyContent:"center",alignItems:"center" }, text:{fontSize:30,fontFamily:"bold",color:"black"}, })