I have code like this:-
export default class TextField extends Component {
constructor(props) {
super(props);
this.state = {
userID: '',
userName: '',
userGmail: '',
userTNumber: '',
};
}
addCustomer = () => {
fetch('http://localhost:3000/send-data', {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
});
} <TextInput
style={styles.inputText}
placeholder="User ID :"
placeholderTextColor="#ffff"
onChangeText={userID => this.setState({userID})}
value={this.state.userID}
autoCapitalize="none"
/>
</View>
}
I Need To Send My Text Input To My Node BackEnd... I Don't Know How To Send My Data Using This Fetch Function
**
addCustomer = () => {
fetch('http://localhost:3000/send-data', {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
});
};
**
I Don't Know How To Put My Text Input Into,
body: JSON.stringify({}),
This Is My BackEnd To Post My Data:-
app.post('/send-data', (req, res) => {
const customer = new Customer({
userID: req.body.userID,
userName: req.body.userName,
userGmail: req.body.userGmail,
userTNumber: req.body.userTNumber,
});
customer
.save()
.then(result => {
console.log(result);
res.send(result);
})
.catch(err => {
console.log(err);
});
});
Can You Help Me ..? ThankYou..!