我正在使用GraphQL订阅来获取新用户时获取更新,一切正常,我正在收到更新,但是我无法从导航标头中更新导航标头中的通知计数渲染方法。
class ContactsList extends Component {
static navigationOptions = ({ navigation }) => {
return {
headerRight: (
<View style={{ flexDirection: 'row' }}>
<View style={{ marginEnd: 5 }}>
<Icon.Button
name="bell"
backgroundColor="#3b5998"
onPress={() => alert('Bell Pressed!!')}>
**//i want update the count here when new contact is created**
</Icon.Button>
</View>
</View>
),
};
};
render() {
return (
<View>
<Subscription
subscription={NEW_NOTIFICATION_SUBSCRIPTION}
variables={{ token: this.state.golbalDashboardToken }} >
{({ data, loading }) => {
if (loading) {
// alert('Loading Subcription');
return <Text>Loading Subscription</Text>
}
if (data) {
**// when new contact is created i will receive the data her**
}
}
}
</Subscription>
</View
);
}
}
创建新用户时,我将收到子标签中的数据
尝试以下:
if (data && data !== oldData) {
**// when new contact is created i will receive the data her**
this.props.navigation.setParams({ data }); // << this
}
在导航中
<Icon.Button
name="bell"
backgroundColor="#3b5998"
onPress={() => alert('Bell Pressed!!')}>
**//i want update the count here when new contact is created**
const newData = navigation.getParam('data'); // this
</Icon.Button>