(props)
| 8 | ); |
| 9 | |
| 10 | const 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 | |
| 46 | export default App; |
nothing calls this directly
no test coverage detected