Skip to content

Instantly share code, notes, and snippets.

@JWLangford
Last active January 2, 2021 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JWLangford/13b553d0b1188c9255d6c0e1a5e64326 to your computer and use it in GitHub Desktop.
Save JWLangford/13b553d0b1188c9255d6c0e1a5e64326 to your computer and use it in GitHub Desktop.
import * as React from "react";
import "./styles.css";
import useTest from "./hook";
interface User {
name: string;
email: string;
age: number;
}
export default function App() {
const [getUser, errorMessage, user] = useTest<User>();
return (
<div className="App">
<h1>Simple API Hook Demo</h1>
<button onClick={() => getUser("/users/123")}>Get User</button>
<div>
{user ? (
<div>
<h5>{user.name}</h5>
<h6>{user.email}</h6>
<h6>{user.age}</h6>
</div>
) : (
<h6 style={{ color: "red" }}>{errorMessage}</h6>
)}
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment