how to sent react from data in mongodb

Hello geeks! In this post I have shared the details about “how to sent react from data in mongodb”. Okay, let’s move on to the post.

how to sent react from data in mongodb

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>
    );

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));
    )
);

Final Words

I hope this article helps you to know about “how to sent react from data in mongodb”. If you have any doubts regarding this article please let us know via the comment section. Share this post with your friends and family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment