I am fetching from API multiple TextInputs and displaying them on my screen. So, how can I save the state of user inputs to a global object. Something like this:
state = {
foundtextfields: []
}
Here I am pushing those fetched TextInputs to foundTextFields[] array:
var foundTextFields = [];
foundTextFields.push(<TextInput>{keyvalue_to_json.inputFields[i].placeholderText}</TextInput>)
And I am displaying text inputs in this list:
return (
<View>
{foundtextfields}
</View>
)
EDIT: I want to loop through the state of the array, and extract the key from that ex. “key” (signedbyFullName) and match if that is the same with the json body property "signedbyFullName" like below.
postToBmp = (obje) => {
var userArray = [];
for (i = 0; i < this.myInputFields.myTextFields.length; i++) {
userArray.push(this.myInputFields.myTextFields[i])
console.log("this is the title of al inputFields:", this.myInputFields.myTextFields[i].key)
}
fetch('URL', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Connection': 'Keep-Alive',
},
credentials: 'include',
body: JSON.stringify({
from: '[email protected]',
to: ['<[email protected]>'],
signedByFullName: '',
signedByCPRNumber: '',
otherCompanyName: '',
otherCompanyCVRNumber: ''
})
})
}
TextInputsor just need help to store the values?this.state.foundtextfields.push(…)? if you are doing it in the Modal it self it's normal that it duplicates