# When should you use shouldResubscribe?

**URL:** <https://community.apollographql.com/t/when-should-you-use-shouldresubscribe/6811>\
**Category:** Client SDKs\
**Tags:** client, mobile\
**Created:** [October 6, 2023, 5:33am UTC](https://community.apollographql.com/t/when-should-you-use-shouldresubscribe/6811 "2023-10-06T05:33:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peli](https://avatars.discourse-cdn.com/v4/letter/p/4491bb/32.png) [@Peli](https://community.apollographql.com/u/Peli)\
**Post date:** [October 6, 2023, 5:33am UTC](https://community.apollographql.com/t/when-should-you-use-shouldresubscribe/6811/1 "2023-10-06T05:33:48Z")

</div>

I’m using graphql in a project, and I’m trying to understand the best practices when it comes to subscriptions. When should you use `shouldResubscribe`? When shouldn’t you? I’ve been trying to find information about resubscribing, but I haven’t found that much information.

Specifically I’m trying to figure out whether it would be useful if you delete a post that’s contained within the subscribed data:

Currently I have:

```auto
export const GET_POST = gql`
  query ($offset: Int!, $topic: String) {
    getMessage(offset: $offset, limit: 20, topic: $topic) {
     _id
     sender {
       senderId
     }
      post {
        text
        topic
        dateSent
      }
    }
  }
`;

export const CREATE_POST_MUTATION = gql`
  mutation createPost($input: PostInput!) {
    createPost(input: $input) {
        post {
          text
          dateSent
        }
      }
  }
`;

export const POST_SUBSCRIPTION = gql`
subscription {
  _id
  newPost {
    sender {
      senderId
    }
     post {
       text
        topic
       dateSent
     }
   } 
  }
`;

export default function PostScreen() {

const [createPost,{ data: createPostDate, error:createPostError}] = useMutation(CREATE_POST_MUTATION)
  async function createPostHandler (item: any) {
    createPost({
    variables: { 
    input: { 
       ...
   }, 
  }})
  }
const {data, loading, error, subscribeToMore, fetchMore: fetchMorePosts} = useQuery(GET_POST, {fetchPolicy: 'cache-and-network', variables: { offset: 0, topic: ''}})

 useEffect(() => {
  subscribeToMore({
     document: POST_SUBSCRIPTION,
      updateQuery: (prev, { subscriptionData }) => {
         if (!subscriptionData) {
            return prev;
          }
          const updatePost = subscriptionData.data.updatePost.data;
          const action = subscriptionData.data.updatePost.action;
          if (action === "CREATE") {
              return {
                 getPost:[updatePost, ...prev.getPost]
              };
          }
          else if (action === "DELETE"){
            getPost ...
         },
        onError: err => console.error(err)
      });
}, []);

```

And I’m trying to figure out if it would be considered a good practice/ efficient to resubscribe if `action === "DELETE"`.

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [October 6, 2023, 7:30am UTC](https://community.apollographql.com/t/when-should-you-use-shouldresubscribe/6811/2 "2023-10-06T07:30:55Z")

</div>

`shouldResubscribe` is `true` by default, so you don’t have any need to specify it if you don’t explicitly want to turn it off.

Generally, you’d only want to turn that off if you don’t want the subscription to change when you change e.g. variables.

You can probably safely ignore that option in almost all cases.

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/when-should-you-use-shouldresubscribe/6811/3 "2025-02-06T20:48:12Z")

</div>


