Skip to content

Instantly share code, notes, and snippets.

type ErrorBoundariesProps<TContext> =
| {
children: ReactNode;
errorFallback: ReactNode | ((props: { error: Error }) => ReactNode);
onError?: (error: Error, context: TContext) => void;
}
| {
children: ReactNode;
errorFallback:
// SETUP
function generateData(n) {
const ids = new Array(n).fill(0).map((_, i) => i);
return {
notebooks: ids.map((x) => ({ id: x })),
prices: ids
.map((x) => [
{
entityId: x,
price: 100,
const TEST_DATA = [
["OUTLOOK", "TEMPERATURE", "HUMIDITY", "WIND", "PLAY"],
["SUNNY", "HOT", "HIGH", "WEAK", "NO"],
["SUNNY", "HOT", "HIGH", "STRONG", "NO"],
["OVERCAST", "HOT", "HIGH", "WEAK", "YES"],
["RAIN", "MILD", "HIGH", "WEAK", "YES"],
["RAIN", "COOL", "NORMAL", "WEAK", "YES"],
["RAIN", "COOL", "NORMAL", "STRONG", "NO"],
["OVERCAST", "COOL", "NORMAL", "STRONG", "YES"],
["SUNNY", "MILD", "HIGH", "WEAK", "NO"],

Testing with context

Context

Create a context to wrap the fetch.

import { createContext, useContext } from "react";

const API = {