r/reactjs • u/timmonsjg • Nov 01 '18
Needs Help Beginner's Thread / Easy Questions (November 2018)
Happy November! ๐
New month means new thread ๐ - October and September here.
I feel we're all still reeling from react conf and all the exciting announcements! ๐
Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! Weโre a friendly bunch. No question is too simple. ๐ค
๐ Want Help with your Code? ๐
- Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!
- Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.
New to React?
๐ Here are great, free resources! ๐
40
Upvotes
View all comments
1
u/pangolino91 Nov 04 '18
Hello! I have a question regarding forms / data fetching / POST /GET requests.
In Node.js making an http request in kinda easy. I download npm mySQL and then I simply connect with my database (I am using Hostgator as provider) and make the requests I want.
How to do it in React though? I have a bit of confusion in my mind on how exactly we communicate with the database. Let's suppose I want to create a form in my component and when I submit the datas they get stored in my Database. How do I connect with the database? I tried with fetch() method but I get lost in the syntax:
โfetch('https://mywebsite.com/endpoint/', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ firstParam: 'yourValue', secondParam: 'yourOtherValue', }) })
What should I write in the website url? the address of the Hostgator website? Where do I put the password to my database and where the user?
Sorry for the newbieness of the question but I am really lost...
Thanks in advance