|
1 |
| -import { matchPath, NavLink, useLocation } from 'react-router' |
| 1 | +import { NavLink } from 'react-router' |
2 | 2 |
|
3 | 3 | interface MenuItem {
|
4 | 4 | title: string
|
@@ -31,28 +31,34 @@ const menuItems: Array<MenuItem> = [
|
31 | 31 | },
|
32 | 32 | ] as const
|
33 | 33 |
|
34 |
| -function MenuItemsList(props: { items: Array<MenuItem> }) { |
35 |
| - const location = useLocation() |
36 |
| - |
| 34 | +function MenuItemsList({ items }: { items: Array<MenuItem> }) { |
37 | 35 | return (
|
38 | 36 | <ul className="ml-4">
|
39 |
| - {props.items.map((item) => { |
40 |
| - const isActive = matchPath( |
41 |
| - { path: item.url, end: false }, |
42 |
| - location.pathname, |
43 |
| - ) |
44 |
| - |
45 |
| - // 🐨 Right-click on the gutter next to the line with the `return` |
46 |
| - // and choose "Add Conditional Breakpoint...". |
47 |
| - // 🐨 Enter `item.title === 'Dashboard'` as the breakpoint's condition. |
| 37 | + {items.map((item) => { |
48 | 38 | return (
|
49 | 39 | <li key={item.url}>
|
50 | 40 | <NavLink
|
51 | 41 | to={item.url}
|
52 |
| - className={[ |
53 |
| - 'px-2 py-1 hover:text-blue-600 hover:underline', |
54 |
| - isActive ? 'font-bold text-black' : 'text-gray-600', |
55 |
| - ].join(' ')} |
| 42 | + className={({ isActive }) => |
| 43 | + [ |
| 44 | + 'px-2 py-1 hover:text-blue-600 hover:underline', |
| 45 | + |
| 46 | + // You will be adding a Conditional breakpoint on this line. |
| 47 | + // But before you do, there's a slight problem. Conditions can only access |
| 48 | + // variable from the current scope (the `className` function), and our `item` |
| 49 | + // lives in the parent scope. |
| 50 | + // |
| 51 | + // 🐨 Reference the `item` here to be used in the condition for the breakpoint. |
| 52 | + // 💰 item && isActive |
| 53 | + // |
| 54 | + // 🐨 Next, right-click on the gutter to the left of this line and choose |
| 55 | + // the "Add Conditional Breakpoint..." option. Enter `item.title === 'Dashboard'` |
| 56 | + // as the condition for the breakpoint. |
| 57 | + // |
| 58 | + // 🐨 Finally, run the main menu test suite in the debug mode to see what's wrong. |
| 59 | + isActive ? 'font-bold text-black' : 'text-gray-600', |
| 60 | + ].join(' ') |
| 61 | + } |
56 | 62 | >
|
57 | 63 | {item.title}
|
58 | 64 | </NavLink>
|
|
0 commit comments