---
title: "Comment by auesako on \"Build a chat app in 9 minutes with AWS Amplify & Next JS\" | Hashnode"
description: "Nice blog! I also recommend to update index.js to avoid duplicate subscription that Gabriel E mentioned too. // Subscribe to creation of message const subscript"
url: "https://hashnode.com/posts/aws-amplify-live-chat/609f8a36ebf598658125a988/comment/62602f0e7019274627fd7c5b"
---

[Discussion](https://hashnode.com/posts/aws-amplify-live-chat/609f8a36ebf598658125a988)

Comment [Build a chat app in 9 minutes with AWS Amplify & Next JS](https://hashnode.com/posts/aws-amplify-live-chat/609f8a36ebf598658125a988)

[auesako](https://hashnode.com/@auesako)

[Apr 20, 2022](https://hashnode.com/posts/aws-amplify-live-chat/609f8a36ebf598658125a988/comment/62602f0e7019274627fd7c5b)

Nice blog! I also recommend to update index.js to avoid duplicate subscription that Gabriel E mentioned too.

```
    // Subscribe to creation of message
    const subscription = API.graphql(
      graphqlOperation(onCreateMessage)
    ).subscribe({
      next: ({ provider, value }) => {
        setStateMessages((stateMessages) => [
          ...stateMessages,
          value.data.onCreateMessage,
        ]);
      },
      error: (error) => console.warn(error),
    });
    return () => subscription.unsubscribe()
  }, []);
```
