Skip to content

Instantly share code, notes, and snippets.

View PeteDuncanson's full-sized avatar

Pete Duncanson PeteDuncanson

View GitHub Profile
import { DataStore, Hub, Predicates, syncExpression } from "aws-amplify";
import React, { useCallback, useEffect, useLayoutEffect } from "react";
import {
Address,
Customer,
} from "models";
export type DataStoreZone = "DEFAULT" | "ELEVATED";
@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";
// https://github.com/tompipe/Umbraco-CMS/blob/bdbc37810655c0a4ec860d211ab3a8bf91863ead/src/umbraco.controls/Property.cs
// Replaces from line 46 onwards
writer.WriteLine("<div class=\"umb-el-wrap " + CssClass + "\">");
if (_text != string.Empty)
{
if (_control == null)
{
<form>
<legend>Form #1</legend>
<fieldset>
<p>
<label for="myInput">Tap in the box &gt;&gt;</label>