Migrate to 2.x

Version 2.x replaces the old component/ref model with a hook-and-view model.

TIP

This page is a short migration note for readers inside the 1.x docs. For the full and latest migration guide, see the 2.x migration from 1.x guide.

1.x2.x
YoutubePlayer componentuseYouTubePlayer + YoutubeView
callback propsuseYouTubeEvent
ref.current?.play()player.play()
component props hold confighook config holds player options

Component replacement

Before:

import { YoutubePlayer } from 'react-native-youtube-bridge';

<YoutubePlayer source="AbZH7XWDW_k" />;

After:

import { YoutubeView, useYouTubePlayer } from 'react-native-youtube-bridge';

const player = useYouTubePlayer('AbZH7XWDW_k');

<YoutubeView player={player} />;

Event migration

Before:

<YoutubePlayer onReady={handleReady} onStateChange={handleStateChange} />

After:

useYouTubeEvent(player, 'ready', handleReady);
useYouTubeEvent(player, 'stateChange', handleStateChange);

Control migration

Before:

playerRef.current?.play();

After:

player.play();