I am implementing push notifications in a react native project, where from the parent component of the application I need to pass parameters through the reactNavigation screenProps for a BottomTabNavigator.
(我正在React本机项目中实现推送通知,在该项目中,我需要从应用程序的父组件中通过BottomTabNavigator的reactNavigation screenProps传递参数。)
Once I receive a notification, and I change the status to update the parameter that will indicate to the child components that must be updated, a complete re-rendering of the application is made.(一旦收到通知,并且更改状态以更新将指示必须更新的子组件的参数,就将对应用程序进行完整的重新呈现。)
This is my code:(这是我的代码:)
class AppLayout extends Component {
state = {
updatePushNotifications: false
}
handleActivatePushNotifications = () => {
this.handlePushNotificationMessageListener();
}
handlePushNotificationMessageListener = async () => {
this.notificationListener = firebase.notifications().onNotification((notification) => {
const { title, body } = notification;
console.log(notification);
console.log('notificationListener');
//SETSTATE FOR UPDATE CALLS IN CHILD COMPONENTS
this.setState({
updatePushNotifications: true
});
this.showAlert(title, body);
});
}
showAlert = (title, message) => {
Alert.alert(
title,
message,
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{cancelable: false},
);
}
// The entire navigation component is re-rendered once the setState is executed
render () {
return (
<Layout
screenProps={{
updatePushNotifications: this.state.updatePushNotifications
}}
/>
);
}
}
How can I prevent a re-render of the application when I update any of the parameters that I am passing through the screenProps?
(更新通过screenProps传递的任何参数时,如何防止应用程序重新呈现?)
Thanks in advance for any help
(预先感谢您的任何帮助)
ask by Cesar Rivas translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…