Skip to content

Commit cf78b02

Browse files
committed
new starting point for lesson
1 parent 13908c7 commit cf78b02

File tree

2 files changed

+10
-8
lines changed
  • react/advanced-compound-components/04-compound-component-tabs/practice

2 files changed

+10
-8
lines changed

react/advanced-compound-components/04-compound-component-tabs/practice/Tabs.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { wrapEvent } from '../../utils'
44
// You know what to do 😉
55

66
// Hint: You probably need three contexts
7-
const TabsContext = createContext()
8-
const TabContext = createContext()
9-
const PanelContext = createContext()
7+
const TabsContext = createContext() // For passing general top-level info down
8+
const TabListContext = createContext() // For passing index down from TabList to Tab
9+
const TabPanelsContext = createContext() // Same but index down from TabPanels to TabPanel
1010

1111
export const Tabs = ({ children, ...props }) => {
1212
return (
@@ -29,9 +29,9 @@ export const TabList = ({ children, ...props }) => {
2929

3030
export const Tab = ({ children, ...props }) => {
3131
return (
32-
<div {...props} data-tab="">
32+
<button {...props} data-tab="" role="tab">
3333
{children}
34-
</div>
34+
</button>
3535
)
3636
}
3737

react/advanced-compound-components/04-compound-component-tabs/practice/Tasks.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ export function TaskOne() {
1010
</li>
1111
<li>
1212
We're going to need to know the index of each tab. You'll need to iterate the `children` of
13-
`TabList` which are the Tabs. Use `React.Children.map` and pass the index of the Tab to it.
14-
You could use `React.cloneElement` but there are some drawbacks. Another way is to create
15-
another type of context so we can pass index down from `TabList` to `Tab`.
13+
`TabList`. The children of `TabList` is `Tab`. Use `React.Children.map` to get the index and
14+
pass it to each Tab. You could use `React.cloneElement` but there are some drawbacks.
15+
Another way is to create another type of context so we can pass index down from `TabList` to
16+
`Tab`. Note that you'll need a different context provider than the main `TabsContext`. We
17+
made a context for you already called `TabListContext`
1618
</li>
1719
<li>
1820
For the panels, use the HTML `hidden` attribute to hide panels that are not active. Note,

0 commit comments

Comments
 (0)