how to sent react from data in mongodb
app.post('/stored', (req, res) => {
console.log(req.body);
db.collection('quotes').insertOne(req.body, (err, data) => {
if(err) return console.log(err);
res.send(('saved to db: ' + data));
})
});
handleSubmit(){
let databody = {
"name": this.state.nameIn,
"quote": this.state.quoteIn
}
return fetch('http://localhost:5002/stored', {
method: 'POST',
body: JSON.stringify(databody),
headers: {
'Content-Type': 'application/json'
},
})
.then(res => res.json())
.then(data => console.log(data));
}
render(){
return (
<div>
<form onSubmit={this.handleSubmit}>
<label>
Name
<input type="text" name="name" value={this.nameIn} onChange={this.handleNameChange}/>
</label>
<label>
quote
<input type="text" name="quote" value={this.quoteIn} onChange={this.handleQuoteChange}/>
</label>
<input type="submit" value="Add to DB" />
</form>
</div>
);
}
Also in JavaScript:
- reactnode prop-types
- count characters in typescript
- reverse number in js
- cypress fixture
- js pow
- get data from column in table js
- javascript replace all occurrences of string
- python object to json
- e.target javascript
- javascript get the last element of an array
- express unique validator for the owner
- jquery animation
- string parameter javascript function
- discord.js say command embed
- ReferenceError: fetch is not defined
- javascript const
- readfile nodejs
- sass node sass loder
- how to make apk react native
- how to get a user input in js
- object get property with max value javascript
- javascript range of integers
- foreach async typescript
- col to right bootstrap