Skip to content

Commit 0c82951

Browse files
committed
re-work some remix lessons
1 parent 1107597 commit 0c82951

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

remix/lessons/05-forms-and-actions/lecture/routes/_products-layout._index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export default function ProductsIndex() {
8181
onClick={() => addToCart(product.id)}
8282
className="button button-outline whitespace-nowrap"
8383
type="submit"
84+
aria-label="Add To Cart"
8485
>
8586
<Icon name="cart" /> {quantityInCart > 0 && quantityInCart}
8687
</button>

remix/lessons/05-forms-and-actions/lecture/routes/_products-layout.final.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ function AddToCart({ productId, quantityInCart = 0 }: AddProps) {
7474
<fetcher.Form method="post">
7575
<input type="hidden" name="productId" value={productId} />
7676
<input type="hidden" name="quantity" value={quantityInCart + 1} />
77-
<button type="submit" className="button button-outline whitespace-nowrap">
77+
<button
78+
type="submit"
79+
className="button button-outline whitespace-nowrap"
80+
aria-label="Add To Cart"
81+
>
7882
<Icon name="cart" /> {quantityInCart > 0 && quantityInCart}
7983
</button>
8084
</fetcher.Form>

remix/lessons/05-forms-and-actions/practice-final/components/CartButtons.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export function AddToCart({ productId, quantityInCart = 0 }: AddProps) {
1313
<fetcher.Form method="post" action="/cart">
1414
<input type="hidden" name="productId" value={productId} />
1515
<input type="hidden" name="quantity" value={quantityInCart + 1} />
16-
<button type="submit" className="button button-outline whitespace-nowrap">
16+
<button
17+
type="submit"
18+
className="button button-outline whitespace-nowrap"
19+
aria-label="Add To Cart"
20+
>
1721
<Icon name="cart" /> {quantityInCart > 0 && quantityInCart}
1822
</button>
1923
</fetcher.Form>

remix/lessons/05-forms-and-actions/practice/GUIDE.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ When the app gets bigger, we'll want a more general route for the cart action --
2121

2222
1. Move the action in `_products-layout._index.tsx` function and it's dependencies (imports) to a new file at `routes/cart.tsx`.
2323
2. Refactor your `<Form>` components to have an action prop that points to this new path. By default, the lack of an action told Redux to send your data to the same path you're on which is why you didn't need an action before.
24+
3. Refactor the `<Form>`s to be `<fetcher.Form>` instead.
25+
4. You'll need to call `useFetcher` to get a `fetcher` object which replaces `useNavigation`
2426

25-
Example: `<Form method="post" action="/cart">`
27+
Example: `<fetcher.Form method="post" action="/cart">`
2628

2729
Make sure adding to the cart works before you continue
2830

2931
# Task 3
3032

3133
1. Move the two buttons and their forms to the `components/CartButtons.tsx` file. We'll use this file to export any cart/button related components (two components for now).
3234
2. Some of the work in `CartButtons.tsx` has been done for you. Once you get the code moved, you should make sure it still works and you can add to the cart before you continue.
33-
3. Refactor the `<Form>`s to be `<fetcher.Form>` instead.
34-
4. You'll need to call `useFetcher` to get a `fetcher` object

remix/lessons/05-forms-and-actions/practice/routes/_products-layout._index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ export default function ProductsIndex() {
4545
</div>
4646
<div className="flex gap-2">
4747
{/* Task 1 */}
48-
<button type="submit" className="button button-outline whitespace-nowrap">
48+
<button
49+
type="submit"
50+
className="button button-outline whitespace-nowrap"
51+
aria-label="Add To Cart"
52+
>
4953
<Icon name="cart" /> {quantityInCart > 0 && quantityInCart}
5054
</button>
5155
<button type="submit" className="button">

0 commit comments

Comments
 (0)