viewController.js
// some other code above his
useEffect(() => {
determineAndSetOrientation();
Dimensions.addEventListener('change', determineAndSetOrientation);
return () => {
Dimensions.removeEventListener('change', determineAndSetOrientation);
};
}, []);
console.log(orientation);
return (
<ViewControllerContext.Provider value={{orientation}}>
{props.children}
</ViewControllerContext.Provider>
);
};
HomePage.js
//some other code that bring in viewController.js
viewController = () => {
return {
...(this.props.view.orientation.orientation == 'PORTRAIT'
? this.renderListView()
: this.renderGridView()),
};
};
render() {
return <>{this.viewController()}</>;
}
}
From viewControl.js it only console log when device is rotated however from my HomPage.js which is bringing in the viewController it console logs without stopping
landscape
landscape
landscape
landscape
landscape
question from:
https://stackoverflow.com/questions/66053155/react-native-loop-issues-when-bringing-in-component-from-different-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…