How to detect screen rotation in expo + react native + video player.

I want to rotate the app when the screen has been rotated.
useEffect(() => {
const sub = () => {
if (Dimensions.get(‘window’).height > Dimensions.get(‘window’).width) {
//Device is in portrait mode, rotate to landscape mode.
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
}
else {
//Device is in landscape mode, rotate to portrait mode.
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT);
}
};
const subscribe = ScreenOrientation.addOrientationChangeListener(sub);
return () => {
ScreenOrientation.removeOrientationChangeListener(subscribe);
}
}, );
I used this but doesn’t work, I looking for examples, but I could not found.