Here what am trying to do is , on Picker value change calling the function and trying to call for loop and draw 5 TextInput , but getting error . Please help for this small mistake , when i am trying to call myloop array directly on value change its generating error that array can't be call as function .
import * as React from 'react';
import { Text, View, StyleSheet, Alert, Picker } from 'react-native';
import { Constants } from 'react-native';
import { TextInput } from 'react-native-gesture-handler';
var myloop = [];
;
export default class UiDynamic extends React.Component {
// add a selectValue to your state to stop the overwriting
state = {
PickerValueHolder: [],
selectedValue: ''
}
componentDidMount() {
// remove the return
fetch('http:///Dsenze/userapi/inventory/viewinventorytype', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"username" :"admin",
"password" :"admin"
})
}).then((response) => response.json())
.then((responseJson) => {
// use the inventoryTypeData as it is already an array
let PickerValueHolder = responseJson.inventoryTypeData;
console.log("Array data" , PickerValueHolder)
this.setState({ PickerValueHolder }); // Set the new state
})
.catch((error) => {
console.error(error);
});
}
onPickerValueChange=()=>{
{myloop}
console.log("Picker change" , myloop);
// this.onPickerValueTextinput();
}
render() {
for (let i = 0; i < 5; i++) {
myloop.push(
<View key={<TextInput></TextInput>}>
<TextInput style={{ textAlign: 'center', marginTop: 5 }}
placeholder="Enter your name ">
</TextInput>
</View>
)
}
return (
<View style={styles.container}>
{/* {myloop} */}
{<Picker
selectedValue={this.state.selectedValue}
onValueChange={this.onPickerValueChange}>
{ this.state.PickerValueHolder.map((item, key)=>
<Picker.Item label={item.name} value={item.name} key={key} />
)}
</Picker>}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
}
});
Thanks