Skip to main content

Hooks

useChannelSDK

Primary hook for interacting with the channel. Requires BBChannelProvider as an ancestor in the component tree.

import { useChannelSDK } from '@bluebillywig/react-native-channel';

function MyComponent() {
const {
canGoBack,
currentPage,
isLoading,
error,
goBack,
navigateTo,
navigateToEntity,
search,
reload,
getNavigationState,
setNavigationState,
resetNavigation,
} = useChannelSDK();

return (
<Button
title="Go Back"
disabled={!canGoBack}
onPress={goBack}
/>
);
}

Return value

PropertyTypeDescription
canGoBackbooleanWhether back navigation is available
currentPageBBPageTypeCurrent page type
isLoadingbooleanWhether the channel is loading
errorBBErrorEvent | nullCurrent error, if any
goBack() => voidNavigate back
navigateTo(page: BBPageType) => voidNavigate to a page
navigateToEntity(id: string, type: string, options?: NavigateToEntityOptions) => voidNavigate to a specific entity
search(query: string) => voidPerform a search
reload() => voidReload the channel
getNavigationState() => Promise<BBNavigationState>Get current navigation state
setNavigationState(state: BBNavigationState) => voidSet navigation state
resetNavigation() => voidReset to the main page

Provider setup

Wrap your app (or the relevant subtree) with BBChannelProvider:

import { BBChannelProvider, BBChannel } from '@bluebillywig/react-native-channel';

function App() {
return (
<BBChannelProvider>
<BBChannel channelUrl="https://demo.bbvms.com/ch/1152.json" />
<ControlBar />
</BBChannelProvider>
);
}

useChannelNavigation

Hook focused on navigation state management.

import { useChannelNavigation } from '@bluebillywig/react-native-channel';

function NavigationControls() {
const {
currentPage,
canGoBack,
navigationState,
goBack,
goHome,
openSearch,
navigateToEntity,
navigateToSubChannel,
getState,
setState,
reset,
} = useChannelNavigation();

return (
<View>
<Text>Current: {currentPage}</Text>
<Button title="Home" onPress={goHome} />
<Button title="Back" onPress={goBack} disabled={!canGoBack} />
<Button title="Search" onPress={() => openSearch()} />
</View>
);
}

Return value

PropertyTypeDescription
currentPageBBPageTypeCurrent page type
canGoBackbooleanWhether back navigation is available
navigationStateBBNavigationStateCurrent navigation state
goBack() => voidNavigate back
goHome() => voidNavigate to the main page
openSearch(query?: string) => voidOpen the search page, optionally with a query
navigateToEntity(id: string, type: string, options?: NavigateToEntityOptions) => voidNavigate to a specific entity
navigateToSubChannel(subChannelId: string) => voidSwitch to a sub-channel
getState() => Promise<BBNavigationState>Get current state
setState(state: BBNavigationState) => voidSet navigation state
reset() => voidReset to initial state

Custom hook example

Build your own hooks on top of the SDK:

import { useChannelSDK } from '@bluebillywig/react-native-channel';
import { useCallback } from 'react';

function useDeepLink() {
const { navigateToEntity, getNavigationState } = useChannelSDK();

const openFromDeepLink = useCallback(async (clipId: string) => {
const state = await getNavigationState();
if (state.contentId !== clipId) {
navigateToEntity(clipId, 'mediaclip', { autoPlay: true });
}
}, [navigateToEntity, getNavigationState]);

return { openFromDeepLink };
}