DEV Community

Sachin
Sachin

Posted on

Connecting frontend And Backend In react.js

Connecting React.js Frontend to Backend

create a fresh folder
run the command in the folder directory:-
npm create vite@latest
cd to the given project-name
and run npm install
Enter fullscreen mode Exit fullscreen mode
import { useState ,useEffect } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
import axios from 'axios'
function App() {
   const [data,setData]=useState({});

   useEffect(()=>{
     const fetchData=async ()=>{
        const result=await axios.get("https://jsonplaceholder.typicode.com/posts/1");
        setData(result.data);
     }

     fetchData()
   },[])

   return <div>
     {data ? JSON.stringify(data) : "Loading..."}
   </div>
}

export default App

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Cloudinary image

Need to crop and overlay a logo on 999.999 web images? πŸ–Ό

No problem! Combine hundreds of advanced image effects directly through an API. Discover all you can do with Cloudinary Image and Video APIs.

Discover

πŸ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay