
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
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
The above is the detailed content of Connecting frontend And Backend In react.js. For more information, please follow other related articles on the PHP Chinese website!
The difference between Fahrenheit and Celsius
How to delete blank pages in word without affecting other formats
What does mobile phone hd mean?
How to solve 0xc000409 error
OGG common commands
Can I retrieve a deleted Douyin short video?
AC contactor use
The difference between console cable and network cable