Skip to content

Instantly share code, notes, and snippets.

View pkellner's full-sized avatar
🏠
Working from home

Peter Kellner pkellner

🏠
Working from home
View GitHub Profile
@pkellner
pkellner / App.js
Created May 16, 2022 17:25
A working simple app component that has no Suspense Elements but does use useDeferredValue (and works as expected)
import "./App.css";
import { useState, useDeferredValue, memo, useEffect } from "react";
import { fetchCities } from "./data/cities";
const displayCount = 1000;
// code similar to example by React Team: https://github.com/reactwg/react-18/discussions/129#discussioncomment-2439125
const ListItem = ({ id, name }) => {
let now = performance.now();
while (performance.now() - now < 5) {
@pkellner
pkellner / gist:2503b62f3d015a3a22403703081040e9
Created May 16, 2022 17:24
AppWithUseDeferredValueAndNoSuspenseElement.js
import "./App.css";
import { useState, useDeferredValue, memo, useEffect } from "react";
import { fetchCities } from "./data/cities";
const displayCount = 1000;
// code similar to example by React Team: https://github.com/reactwg/react-18/discussions/129#discussioncomment-2439125
const ListItem = ({ id, name }) => {
let now = performance.now();
while (performance.now() - now < 5) {
import { fetchCities } from "../data/cities";
export function fetchCityListData(displayCount) {
const cityPromise = fetchCities(displayCount);
return {
cities: wrapPromise(cityPromise),
};
}
function wrapPromise(promise) {
@pkellner
pkellner / ErrorBoundary.js
Created January 30, 2022 14:59
ErrorBoundary used in React 18 Pluralsight Course
// Author: Peter Kellner, https://peterkellner.net
import React from 'react';
class ErrorBoundary extends React.Component {
state = { hasError: false };
updateHasErrorsToFalse = () => {
this.setState(() => ({
hasError: false,
}));
function Demo() {
function ProcessAndRender() {
const fetcher = (url) => fetch(url).then((r) => r.json());
const { data } = useSwr(
`https://jsonplaceholder.typicode.com/todos`,
fetcher,
{ suspense: true }
);
return (
<div className="container grid">
function Demo() {
const fetcher = (url) => fetch(url).then((r) => r.json());
const { data } = useSwr(
`https://jsonplaceholder.typicode.com/todos`,
fetcher,
{ suspense: false }
);
if (!data) return <div>Loading... (pre-Suspense)</div>;
@pkellner
pkellner / machine.js
Last active January 26, 2021 01:26
Generated by XState Viz: https://xstate.js.org/viz
const svccUiMachine = Machine({
id: 'svccUiMachine1',
context: {
currentCodeCampYear: '2019',
codeCampYears: [
'2005',
'2006',
'2007',
'2008',
'2009',
@pkellner
pkellner / machine.js
Last active January 26, 2021 00:57
Generated by XState Viz: https://xstate.js.org/viz
svccUiMachine1 = Machine({
id: 'svccUiMachine1',
context: {
currentCodeCampYear: '2019',
codeCampYears: [
'2005',
'2006',
'2007',
'2008',
'2009',
@pkellner
pkellner / machine.js
Last active January 25, 2021 23:57
Generated by XState Viz: https://xstate.js.org/viz
const svccUiMachine1 = Machine({
id: 'svccUiMachine1',
context: {
},
type: 'parallel',
states: {
codeCampYear: {
initial: "2019",
states: {
using System;
using System.Collections.Generic;
namespace WebAppReactCRA.GraphQL.Speakers
{
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class AttendeesAmazonBookDto {
public int Id { get; set; }
public string AmazonImageSmall { get; set; }
public string BookTitle { get; set; }