Skip to content

Commit 959aa5a

Browse files
committed
Fix conditional useEffect
1 parent f78a7ac commit 959aa5a

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

client/channel.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ type Props = {
2222
export function Channel(props: Props) {
2323
const { info, channel, onPlay, onStop, playing } = props
2424

25-
if (!info) {
26-
return null
27-
}
28-
29-
const { name, image, starts, ends, location } = info.now
25+
const { name, image, starts, ends, location } = info?.now ?? {}
3026

3127
function handleClick() {
3228
if (playing) {
@@ -63,6 +59,10 @@ export function Channel(props: Props) {
6359
return () => el.removeEventListener("scroll", handler)
6460
}, [channel])
6561

62+
if (!info) {
63+
return null
64+
}
65+
6666
return (
6767
<div className={css.wrapper} data-show="true" data-channel={channel} ref={ref}>
6868
<div className={classnames(css.channel, playing && css.playing)}>
@@ -108,7 +108,11 @@ export function Channel(props: Props) {
108108
)
109109
}
110110

111-
function formatTime(date: Date | number): string {
111+
function formatTime(date: Date | number | undefined): string {
112+
if (!date) {
113+
return ""
114+
}
115+
112116
return new Date(date).toLocaleTimeString("en-GB", {
113117
hour: "2-digit",
114118
minute: "2-digit",

0 commit comments

Comments
 (0)