Firstly here is my react code: http://pasted.co/bb8b578f
I'm currently attempting to teach myself how to use both nodejs and React on the same project. I followed a tutorial, although it wasn't very straightforward on a lot of things, but fortunately I have worked with both nodejs and react so I believe I was able to accommodate things when it wasn't specified on certain things... the gist of the project is to make a guestbook in which people sign it and add a message, then it's added onto a database (MLab)
I made a very straightforward herokuapp that shows me the database I made, it currently only has a few things... the userSchema i made in nodejs is simple:
var mongoose = require('mongoose');
var UserSchema = new mongoose.Schema({
name: String,
message: String
});
mongoose.model('User', UserSchema);
module.exports = mongoose.model('User');
and the rest works fine, (as in the react app compiles and everything but the post and fetching isn't functioning... nothing happens when i press submit, and no messages are shown from the fetch function -- more details below))
Now, when we get to the react stuff, it seems straightforward, but i have not worked with axios, so i'm not 100% why, but the actual axios.post function does not add onto my database when i submit a signature through the react app. It works fine when i run it locally and use postman though.
The first thing i was going to try to do is to simply use the fetch function which i know works fine when I use a different api, such as the coinmarketcap API, in my code I do have to change it up, but the point is I end up getting the name of bitcoin to show up next to the string "Message: " so i know that I'm doing it right, but for some reason it doesn't work with MY database, or json data.
WHAT I THINK THE PROBLEM IS, however, is that the json data is inside []. You can see it if you go to my heroku app (hyperlinked above), but i'm not really sure, but it IS the only difference I can think of.
Unfortunately, when I try to add a signature, in the react app after i press submit, I don't see anything beind added to the database which i can check in postman as well...
Any suggestions would be greatly appreciated!