# React / CRUD app help

**URL:** <https://forum.freecodecamp.org/t/react-crud-app-help/150921>\
**Category:** General\
**Created:** [October 2, 2017, 3:34am UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921 "2017-10-02T03:34:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rhythm](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rhythm](https://forum.freecodecamp.org/u/Rhythm)\
**Post date:** [October 2, 2017, 3:34am UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/1 "2017-10-02T03:34:06Z")

</div>

I am creating a CRUD application using reactjs and nodejs I have a function that is invoked when user presses button. I want this function ti send data to the pseudo database.

---

<div class="post-metadata">

**Author:** ![JacksonBates](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jacksonbates/32/123402_2.png) [@JacksonBates](https://forum.freecodecamp.org/u/JacksonBates)\
**Post date:** [October 2, 2017, 3:51am UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/2 "2017-10-02T03:51:10Z")

</div>

When you say your are a beginner…how much of a beginner are you? What have you built before?

I’ve worked through a fair portion of the Mongo University (free) course in the past, and found it good at providing all the information necessary to build CRUD apps. They do not focus on React, though, just the backend side of things, if I recall correctly.

[https://university.mongodb.com/courses/M101JS/about](https://university.mongodb.com/courses/M101JS/about)

---

<div class="post-metadata">

**Author:** ![Marmiz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/marmiz/32/74845_2.png) [@Marmiz](https://forum.freecodecamp.org/u/Marmiz)\
**Post date:** [October 2, 2017, 5:10am UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/3 "2017-10-02T05:10:46Z")

</div>

What you ask can easily be accomplished by sending a `post` request to your backend.

(I generally use [axios](https://github.com/axios/axios) as a wrapper to perform a request, but you can use whatever method you prefer, the logic will still be the same.

Just let your react app make a `post` request and pass the relevant data as:

```auto
//react component

onSubmitData() {
  axios.post('yourURL/endpoint', dataToPass)
    .then((response) => // do something with the response if you want)
    .catch((err) => // do something else if we got error)
} 

```

Then simply instruct your node server to listen to post request on that `endpoint` specified as:

```auto
//node server
// assuming that we are already parsing the body request

app.post('/endpoint', (req, res) => {
 // here you can grab the data in the request, perform your action (eg save them into a DB)
 // then perform a response with either success or error for the frontend to listen
const data = req.body.dataToPass;
res.send(`your data is ${data}`)
})

```

Hope it helps 🙂  
p.s. if your app grows a lot you may want to consider an API to easier manage the logic.

---

<div class="post-metadata">

**Author:** ![Rhythm](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rhythm](https://forum.freecodecamp.org/u/Rhythm)\
**Post date:** [October 2, 2017, 5:23am UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/5 "2017-10-02T05:23:15Z")

</div>

Thank you, i will look at those. really thank you for your reply

---

<div class="post-metadata">

**Author:** ![Rhythm](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rhythm](https://forum.freecodecamp.org/u/Rhythm)\
**Post date:** [October 3, 2017, 1:18pm UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/6 "2017-10-03T13:18:59Z")

</div>

i couldnt get a proper understanding of “how to call from database”. I tried coding in different ways and was unable to move forward.

---

<div class="post-metadata">

**Author:** ![JacksonBates](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jacksonbates/32/123402_2.png) [@JacksonBates](https://forum.freecodecamp.org/u/JacksonBates)\
**Post date:** [October 3, 2017, 1:18pm UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/7 "2017-10-03T13:18:16Z")

</div>

As I have already suggested to you, show us your code (github repo is fine if it’s complicated), or parts of a demo (codepen / heroku / glitch).

It helps others to help you if you provide as much detail as possible. What technologies are you using? Is this a Mongo database, or an SQL based one?

There are lots of ways to create a CRUD app depending on your tech choices, and without knowing what you have tried, we can’t know what information will help you aside from saying ‘read the mongo / MySQL / whatever docs’

Also, since this is related to your last post, please add follow up questions to it so new comers to the question have all the context provided in earlier conversations.

---

<div class="post-metadata">

**Author:** ![JacksonBates](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jacksonbates/32/123402_2.png) [@JacksonBates](https://forum.freecodecamp.org/u/JacksonBates)\
**Post date:** [October 3, 2017, 1:19pm UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/8 "2017-10-03T13:19:39Z")

</div>

I just merged this with your previous thread, and retitled it for clarity, given the scope of your questions.

---

<div class="post-metadata">

**Author:** ![Rhythm](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Rhythm](https://forum.freecodecamp.org/u/Rhythm)\
**Post date:** [October 4, 2017, 7:47pm UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/9 "2017-10-04T19:47:44Z")

</div>

I am building a simple crud application using nodejs and reactjs, and facing some issues in the delete part. when i press the delete button, the data from Json database has to get deleted. i tried many codes but couldnt resolve it. Any valuable suggestions will be very useful.

this is the code for client side and server side i had written, the delete part of code has some issue

```auto
class User extends Component {

    delete(event) {
        fetch('/user', {
                method: 'DELETE',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    firstname: this.state.firstname,
                    lastname: this.state.lastname,
                })
            }).then((response) => response.json())
            .then((responseJson) => {
                this.setState({
                    showUsers: false,
                    users: responseJson
                });
                return;
            })
            .catch((error) => {
                throw (error);
            });
        event.preventDefault();
    }

    render() {
        return ( <
            div className = "User" >
            First Name: {
                this.props.firstname
            } < hr / >
            Last Name: {
                this.props.lastname
            } < hr / >
            <
            button onClick = {
                this.getUsers
            }
            className = "button-primary" > EDIT < /button> <
            button onClick = {
                this.delete.bind(this)
            }
            className = "button-
            danger ">DELETE</button> <
            /div>
        )
    }

}

class User extends Component {

    delete(event) {
        fetch('/user', {
                method: 'DELETE',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    firstname: this.state.firstname,
                    lastname: this.state.lastname,
                })
            }).then((response) => response.json())
            .then((responseJson) => {
                this.setState({
                    showUsers: false,
                    users: responseJson
                });
                return;
            })
            .catch((error) => {
                throw (error);
            });
        event.preventDefault();
    }

    render() {
        return ( <
            div className = "User" >
            First Name: {
                this.props.firstname
            } < hr / >
            Last Name: {
                this.props.lastname
            } < hr / >
            <
            button onClick = {
                this.getUsers
            }
            className = "button-primary" > EDIT < /button> <
            button onClick = {
                this.delete.bind(this)
            }
            className = "button-
            danger ">DELETE</button> <
            /div>
        )
    }

}

The following is server side program (Different Folder)

router.delete('/', (req, res) => {
    db.delete(function(err, data) {
        res.json(data)
    });
});

```

---

<div class="post-metadata">

**Author:** ![Marmiz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/marmiz/32/74845_2.png) [@Marmiz](https://forum.freecodecamp.org/u/Marmiz)\
**Post date:** [October 5, 2017, 3:01am UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/11 "2017-10-05T03:01:09Z")

</div>

Would be helpful to have some additional informations about errors you are receiving 🙂

Anyway just by the look at it I’m thinking that if you are receiving a `cannot read property of 'undefined'` or something similar is probably because you have to return the `fetch` promise as:

```auto
 delete(event) {
   return fetch( ....

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:59pm UTC](https://forum.freecodecamp.org/t/react-crud-app-help/150921/12 "2021-01-16T17:59:25Z")

</div>

Closed on January 16, 2021, 5:59pm UTC


