MCPcopy Create free account
hub / github.com/anttiviljami/react-openapi-client / PetDetails

Function PetDetails

examples/cra-example/src/App.js:10–44  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

8);
9
10const PetDetails = (props) => {
11 // useOperation is called right away as an effect
12 const { loading, error, data } = useOperation('getPetById', props.id);
13
14 // useOperationMethod returns a method you can call
15 const [deletePetById, deleteState] = useOperationMethod('deletePetById');
16
17 if (loading || !data) {
18 return <div>Loading...</div>;
19 }
20
21 if (error) {
22 return <div>Error: {error}</div>;
23 }
24
25 return (
26 <div className="App">
27 <img src={data.image} alt={data.name} />
28 <h3>{data.name}</h3>
29 <ul>
30 <li>
31 <strong>id:</strong> {data.id}
32 </li>
33 <li>
34 <strong>status:</strong> {data.status}
35 </li>
36 </ul>
37 <button onClick={() => deletePetById(data.id)} disabled={deleteState.loading}>
38 Delete
39 </button>
40 {deleteState.response && <p>Success!</p>}
41 {deleteState.error && <p>Error deleting pet: {deleteState.error}</p>}
42 </div>
43 );
44};
45
46export default App;

Callers

nothing calls this directly

Calls 2

useOperationFunction · 0.85
useOperationMethodFunction · 0.85

Tested by

no test coverage detected