Skip to content

Commit 0d3cac8

Browse files
committed
04/03: update the problem
1 parent 84063e0 commit 0d3cac8

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

Diff for: exercises/04.debugging/03.problem.breakpoints/src/main-menu.tsx

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { matchPath, NavLink, useLocation } from 'react-router'
1+
import { NavLink } from 'react-router'
22

33
interface MenuItem {
44
title: string
@@ -31,28 +31,34 @@ const menuItems: Array<MenuItem> = [
3131
},
3232
] as const
3333

34-
function MenuItemsList(props: { items: Array<MenuItem> }) {
35-
const location = useLocation()
36-
34+
function MenuItemsList({ items }: { items: Array<MenuItem> }) {
3735
return (
3836
<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) => {
4838
return (
4939
<li key={item.url}>
5040
<NavLink
5141
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+
}
5662
>
5763
{item.title}
5864
</NavLink>

0 commit comments

Comments
 (0)