Skip to content

Commit

Permalink
chore(js): make hooks fix non-breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
puckey committed Sep 14, 2022
1 parent f7c212f commit b895b9c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useEffect, useRef, useState } from 'react';
import { Event, EventsPayloadByEvent, Progress, State } from './interfaces';
import TrackPlayer from './trackPlayer';

/** Get current playback state and subsequent updates */
export const usePlaybackState = () => {
const usePlaybackStateWithoutInitialValue = () => {
const [state, setState] = useState<State | undefined>(undefined);
useEffect(() => {
let mounted = true;
Expand Down Expand Up @@ -35,6 +34,12 @@ export const usePlaybackState = () => {
return state;
};

/** Get current playback state and subsequent updates */
export const usePlaybackState = () => {
const state = usePlaybackStateWithoutInitialValue();
return state ?? State.None;

This comment has been minimized.

Copy link
@dcvz

dcvz Sep 14, 2022

Contributor

Do we want to leave ourselves a note somewhere that we may want to change this in the future to undefined?

};

/**
* Attaches a handler to the given TrackPlayer events and performs cleanup on unmount
* @param events - TrackPlayer events to subscribe to
Expand Down Expand Up @@ -88,7 +93,7 @@ export function useProgress(updateInterval = 1000) {
duration: 0,
buffered: 0,
});
const playerState = usePlaybackState();
const playerState = usePlaybackStateWithoutInitialValue();
const isNone = playerState === State.None;
useEffect(() => {
let mounted = true;
Expand Down

0 comments on commit b895b9c

Please sign in to comment.