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)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series