How to use the @aws-amplify/datastore.DataStore.observe function in @aws-amplify/datastore

To help you get started, we’ve selected a few @aws-amplify/datastore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sebsto / amplify-datastore-js-e2e / src / App.js View on Github external
useEffect( () => {
    
    const subscription = DataStore.observe(Post).subscribe(msg => {
      console.log(msg.model, msg.opType, msg.element);
      listPosts(setPosts);
    });

    const handleConnectionChange = () => {
      const condition = navigator.onLine ? 'online' : 'offline';
      console.log(condition);
      if (condition === 'online') { listPosts(setPosts); }
    }
    
    window.addEventListener('online', handleConnectionChange);
    window.addEventListener('offline', handleConnectionChange);
       
    return () => subscription.unsubscribe();
  }, []);

@aws-amplify/datastore

AppSyncLocal support for aws-amplify

Apache-2.0
Latest version published 4 days ago

Package Health Score

92 / 100
Full package analysis

Similar packages