This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
forked from codesquad-members-2023/FineAnts-team-02
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5 refactor: NavBar Item들을 직접 넘겨주는 방식으로 수정
- Loading branch information
Showing
3 changed files
with
63 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
|
||
type Props = { | ||
navItems: React.ReactElement[]; | ||
style?: React.CSSProperties; | ||
children: React.ReactNode; | ||
}; | ||
|
||
const NavContext = React.createContext({ navItems: [<div>initial</div>] }); | ||
|
||
export function NavBar({ navItems, style, children }: Props) { | ||
const contextValue = { navItems }; | ||
|
||
return ( | ||
<NavContext.Provider value={contextValue}> | ||
<nav style={style}>{children}</nav> | ||
</NavContext.Provider> | ||
); | ||
} | ||
|
||
export function NavList({ | ||
children, | ||
style, | ||
}: { | ||
children: React.ReactNode; | ||
style: React.CSSProperties; | ||
}) { | ||
return <ul style={style}>{children}</ul>; | ||
} | ||
|
||
export function NavItem() { | ||
const { navItems } = React.useContext(NavContext); | ||
|
||
return ( | ||
<> | ||
{navItems.map((navItem, idx) => ( | ||
<li key={idx}>{navItem}</li> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
NavBar.NavList = NavList; | ||
NavBar.NavItem = NavItem; |
This file contains 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