Привет, ребята, поэтому мне нужно сначала экраны чатов, а второй чат.
В первом у меня есть каналы чата, где я выбираю один, а затем я иду на второй экран, где я на самом делев чате.На втором экране я использую componentWillReceiveProps
для подписок в GraphQL.Все работает нормально, пока я не использую this.props.navigation.goBack()
и если я вернусь, сообщения будут отправлены, но componentWillReceiveProps
больше никогда не вызывается.
componentWillReceiveProps(nextProps) {
console.log('I am here')
if (nextProps.data !== undefined && !nextProps.data.loading) {
let { subscribeToMore } = this.props.data;
subscribeToMore({
document: MESSAGE_ADDED_SUBSCRIPTION,
updateQuery: (previousResult, { subscriptionData }) => {
if (!subscriptionData.data) {
return previousResult;
}
const newMessage = subscriptionData.data.messageAdded;
if (
previousResult.getMessagesForThisChannel[0] === undefined ||
previousResult.getMessagesForThisChannel[0].channel._id ===
newMessage.channel._id
) {
if (
!previousResult.getMessagesForThisChannel.find(
n => n._id === newMessage._id
)
) {
return {
...previousResult,
getMessagesForThisChannel: [
{ ...newMessage },
...previousResult.getMessagesForThisChannel
]
};
}
}
return previousResult;
},
onError: err => console.log(err)
});
}
}