[Vuejs]-Aws amplify update my Vuex state on DynamoDB table update using triggers

0👍

You can use subscription provided by AppSync GraphQL. It will handle DynamoDB trigger itself.


import { API, graphqlOperation } from "aws-amplify";
import { onUpdatePlayer } from "../../graphql/subscriptions"; 

Here’s Reactjs specific code

const PlayerComponent = () => {
  let subscriptionOnUpdate;

  const setupSubscriptions = () => {
    subscriptionOnUpdate = API.graphql(
      graphqlOperation(onUpdatePlayer)
    ).subscribe({
      next: () => {
        // do stuff like updating other state 
      },
    })
  }

  useEffect(() => {
    setupSubscriptions();

    return () => {
      subscriptionOnUpdate.unsubscribe()
    }
  }, [])
  
}

Leave a comment