react-native-google-cast
Version:
React Native wrapper for the Google Cast SDK for iOS and Android
30 lines (28 loc) • 780 B
JavaScript
import { useEffect, useState } from 'react';
import useCastSession from './useCastSession';
/**
* Hook that provides the currently connected {@link Device}.
*
* @returns current device, or `null` if there's no session connected
* @example
* ```js
* import { useCastDevice } from 'react-native-google-cast'
*
* function MyComponent() {
* const castDevice = useCastDevice()
*
* if (castDevice) {
* console.log(castDevice)
* }
* }
* ```
*/
export default function useCastDevice(options) {
const [device, setDevice] = useState(null);
const session = useCastSession(options);
useEffect(() => {
if (!session) setDevice(null);else session.getCastDevice().then(setDevice);
}, [session]);
return device;
}
//# sourceMappingURL=useCastDevice.js.map