Skip to content

Commit

Permalink
Example of calling API
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwhitney committed May 27, 2024
1 parent d2ac694 commit e10fbab
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import reactLogo from './assets/react.svg';
import './App.css'

function App() {
const [count, setCount] = useState(0)
const [message, setMessage] = useState('Loading...');

useEffect(() => {
fetch('/api')
.then((res) => res.json())
.then((data) => setMessage(data.message));
}, []);

return (
<>
Expand All @@ -28,6 +35,9 @@ function App() {
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
<p>
Message from `/api`: <span>{message}</span>
</p>
</>
)
}
Expand Down

0 comments on commit e10fbab

Please sign in to comment.