I cant seem to render the dropdown items.Not sure I have the syntax right, but the log shows
{menu: Array(5)}
menu: (5) ['Guitar', 'Ams Work', 'Learning', 'Food', 'Exercise']
Heres the relevent code.
const data = ["Guitar", "Ams Work","Learning","Food","Exercise"]
function App() {
return (
<div className="container">
<Header />
<ToggleVisibility basicexample={<MyDropdown menu = {data}/>} />
<Footer />
</div>
);
}
….
function MyDropdown(menu) {
console.log(menu)
return (
<Dropdown>
<Dropdown.Toggle variant="success" id="dropdown-basic">
Dropdown Button
</Dropdown.Toggle>
<Dropdown.Menu >
<Dropdown.Item href="#/action-1">{menu[0]}</Dropdown.Item>
<Dropdown.Item href="#/action-2">{menu[1]}</Dropdown.Item>
<Dropdown.Item href="#/action-3">{menu[2]}</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
);
}
2
Answers
The only argument given to a function component is the props, which is an object. You could destructure it to access the
menu
prop.Then, use
Array#map
to render aDropdown.Item
for each element of the array.Change
menu
–To
props
–The menu is accessible via
props.menu
–TypeScript –