From c193e5da2dfe97370ae82626e62660d399e54069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Tue, 5 Dec 2023 02:21:38 +0100 Subject: [PATCH] Replace menu with functional component --- src/js/menu.tsx | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/js/menu.tsx b/src/js/menu.tsx index bc947e3..59d5dc0 100644 --- a/src/js/menu.tsx +++ b/src/js/menu.tsx @@ -3,43 +3,37 @@ import React from "react"; type StreamSelectCallback = (selected: string) => void -type MenuProps = { +interface MenuProps { items: string[] - selectedItem: string | undefined + selectedItem: string | null selectCallback: StreamSelectCallback } -export class Menu extends React.Component { - constructor(props: MenuProps) { - super(props) - } - - render() { - return ( - - ) - } - - private menuitems() { +export function Menu({ items, selectedItem, selectCallback }: MenuProps) { + const menuitems = () => { return ( <> - {this.props.items.map((value, idx) => { - if (this.props.selectedItem == value) { + {items.map((value, idx) => { + if (selectedItem == value) { return
  • {value}
  • } else { return
  • { - this.props.selectCallback(value) + selectCallback(value) }} className="menu-item">{value}
  • } })} ) } + return ( + + ) + }