Skip to content

Instantly share code, notes, and snippets.

@chunleng
Created August 9, 2021 14:55
Show Gist options
  • Save chunleng/a6f857f2b008cff7079948f96a98b94c to your computer and use it in GitHub Desktop.
Save chunleng/a6f857f2b008cff7079948f96a98b94c to your computer and use it in GitHub Desktop.
Medium: OpenAPI and CodeGen - React
import React from "react";
import { Bar, FirstApi } from "./gen/api";
function App() {
const [bar, setBar] = React.useState<Bar>({})
React.useEffect(() => {
new FirstApi(undefined, "http://localhost:8000").getFoo().then((res) => {
setBar(res.data);
});
}, [])
return <ul>{bar.items?.map(x => <li key={x}>{x}</li>)}</ul>
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment