This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderService { | |
static async list() { | |
const orders = await api.get('/api/orders'); | |
return orders; | |
} | |
static async delete(id) { | |
await api.delete(`/api/orders/${id}`); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import OrderService from './OrderService'; | |
class Orders { | |
constructor(props) { | |
super(props); | |
this.state = { | |
orders: [], | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react'; | |
import OrderService from './OrderService'; | |
function useOrders() { | |
const [orders, setOrders] = useState([]); | |
async function fetchOrders() { | |
const orders = await OrderService.get(); | |
setOrders(orders); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Orders.js | |
import React from 'react'; | |
import useOrders from './useOrders'; | |
function Orders() { | |
const { orders } = useOrders(); | |
return ( | |
<div> | |
<h1>Orders</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OrdersListItem.js | |
import React from 'react'; | |
import OrderDeleteButton from './OrderDeleteButton'; | |
function OrdersListItem(props) { | |
const { order } = props; | |
return ( | |
<li> | |
<h2>{order.title}</h2> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Orders.js | |
import React from 'react'; | |
import OrderService from './OrderService'; | |
class Orders { | |
constructor(props) { | |
super(props); | |
this.state = { | |
orders: [], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Orders.js | |
return ( | |
... | |
<OrdersList | |
orders={orders} | |
onRemoveItem={this.handleRemove} | |
/> | |
... | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// useOrders.js | |
import { useState, useEffect } from 'react'; | |
import OrderService from './OrderService'; | |
function useOrders() { | |
const [orders, setOrders] = useState([]); | |
async function fetchOrders() { | |
const orders = await OrderService.get(); | |
setOrders(orders); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// useOrders.js | |
import { useState, useEffect } from 'react'; | |
import OrderService from './OrderService'; | |
function useOrders() { | |
const [orders, setOrders] = useState([]); | |
function createDeleteHandler(id) { | |
return async function () { | |
await OrderService.delete(id); |
OlderNewer