import * as React from "react"; import { useState } from "react"; import { Channel, Props } from ".."; function useChannelSelect( channels: Channel[], onChannelPressInterceptor?: (channel: Channel) => void, open?: boolean ) { const [channelSelectedIndex, setChannelSelectedIndex] = useState(0); function onChannelPress(channel: Channel, index: number) { setChannelSelectedIndex(index); if (onChannelPressInterceptor) onChannelPressInterceptor(channel); } return { open, currentChannel: channels[channelSelectedIndex], channelSelect: { channels, channelSelectedIndex, onChannelPress, }, }; } export default useChannelSelect;