创建新用户时,我正在使用graphql订阅获取更新,一切正常,我正在接收更新,但是无法从render方法更新导航头中的通知计数。
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
);
}
}
创建新用户后,我将在Subcription标记内接收数据
答案 0 :(得分:1)
尝试一下:
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>