Skip to content

Instantly share code, notes, and snippets.

View PeteDuncanson's full-sized avatar

Pete Duncanson PeteDuncanson

View GitHub Profile
@PeteDuncanson
PeteDuncanson / usage.ts
Created September 24, 2021 09:45 — forked from wesleycole/usage.ts
Hooks for working with Amplify's DataStore library
function App() {
const { data, isLoading, error, refetch } = useQuery(
async () => await DataStore.query(Model),
);
const { handler, isLoading, isError, isSuccess } = useMutation<Model>(async (variables) => {
await DataStore.save(new Sermon(template));
});
useSubscription(() => DataStore.observe(Model), {
@PeteDuncanson
PeteDuncanson / useDataStoreQuery.tsx
Last active October 7, 2021 19:48 — forked from arabold/useDataStoreQuery.tsx
Simplify querying the Amplify DataStore using React hooks
import {
DataStore,
PersistentModel,
PersistentModelConstructor,
ProducerModelPredicate,
SortPredicate,
ProducerPaginationInput,
} from "@aws-amplify/datastore";
import { useAppState } from "providers/AppStateProvider";
import { useCallback, useEffect, useRef, useState } from "react";
<form>
<legend>Form #1</legend>
<fieldset>
<p>
<label for="myInput">Tap in the box &gt;&gt;</label>