Skip to content

Instantly share code, notes, and snippets.

@ricardocuellar
Last active November 3, 2025 17:06
Show Gist options
  • Select an option

  • Save ricardocuellar/049f9e93cffa1ae639912ced2eb2b2ee to your computer and use it in GitHub Desktop.

Select an option

Save ricardocuellar/049f9e93cffa1ae639912ced2eb2b2ee to your computer and use it in GitHub Desktop.
Sección 15 - CorsDemo - App.jsx
import { useState } from "react";
function App() {
const [data, setData] = useState(null);
const [error, setError] = useState(null);
const fetchData = async () => {
setData(null);
setError(null);
};
return (
<div style={{ fontFamily: "sans-serif", padding: 30 }}>
<h1>Demo CORS con FastAPI</h1>
<p>
Este ejemplo intenta conectar con la API en <b>http://127.0.0.1:8000</b>
</p>
<button
onClick={fetchData}
style={{
background: "#3182ce",
color: "white",
padding: "10px 20px",
border: "none",
borderRadius: 6,
cursor: "pointer",
fontSize: "16px",
}}
>
Probar conexión
</button>
{data && (
<pre
style={{
marginTop: 20,
background: "#1a202c",
color: "#f7fafc",
padding: 15,
borderRadius: 8,
}}
>
{JSON.stringify(data, null, 2)}
</pre>
)}
{error && (
<pre
style={{
marginTop: 20,
background: "#fed7d7",
color: "#742a2a",
padding: 15,
borderRadius: 8,
}}
>
{error}
</pre>
)}
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment