Skip to content

Instantly share code, notes, and snippets.

View rmdort's full-sized avatar

Vinay M rmdort

View GitHub Profile
:root {
--rnc-background: 0 0% 100%;
--rnc-foreground: 222.2 47.4% 11.2%;
--rnc-muted: 0 0% 90.9%;
--rnc-muted-foreground: 215.4 16.3% 46.9%;
--rnc-popover: 0 0% 100%;
--rnc-popover-foreground: 222.2 47.4% 11.2%;
--rnc-card: 0 0% 100%;
--rnc-card-foreground: 222.2 47.4% 11.2%;
--rnc-border: 0 0% 78.0%;
// Setup
const { onIncreaseIndent, onDecreaseIndent } = useSpreadsheetState()
return (
<CanvasGrid
onIncreaseIndent={onIncreaseIndent}
onDecreaseIndent={onDecreaseIndent}
/>
)
// Option 1 - With useSpreadsheetState hook
// Calculator has to expose the following functions
/*
getPrecedents,
getPrecedentsFromFormulaString,
getDependents,
getGraphNodes,
*/
export const Spreadsheet = () => {
import { useCallback, useRef, useSyncExternalStore } from "react";
export const useAsyncHook = <T>(fn: () => Promise<T> | undefined) => {
const resultRef = useRef<T>();
const getSnapShot = () => resultRef.current;
const subscribe = useCallback(
(onStoreChange: () => void) => {
const executeAsync = async () => {
try {
const result = await fn?.();
@rmdort
rmdort / use-memo-compare.ts
Created March 11, 2022 15:35
Cache a variable across render
import { useRef, useLayoutEffect } from "react";
export const useMemoCompare = <T>(
next: T,
compare: (previous: T | undefined, next: T) => boolean
): T => {
const previousRef = useRef<T>();
const previous = previousRef.current;
const isEqual = compare(previous, next);
@rmdort
rmdort / use-resize-observer.ts
Created February 26, 2022 11:58
use-resizer-observer hook
import { useRef, useLayoutEffect, useState, useCallback } from "react";
type HTMLOrSVGElement = HTMLElement | SVGElement;
export type RectReadOnly = {
readonly x: number;
readonly y: number;
readonly width: number;
readonly height: number;
readonly top: number;
@rmdort
rmdort / index.md
Created June 23, 2021 03:16 — forked from bvaughn/index.md
How to use profiling in production mode for react-dom
@rmdort
rmdort / App.web.tsx
Created June 5, 2021 13:05 — forked from arrygoo/App.web.tsx
React Native Web configuration
import React, {useState} from 'react';
import {View, Text, TouchableOpacity, StyleSheet} from 'react-native';
const App = () => {
const [count, setCount] = useState(0);
return (
<View style={styles.container}>
<Text style={styles.title}>Hello from {'\n'}React Native Web!</Text>
<TouchableOpacity
onPress={() => setCount(count + 1)}
@rmdort
rmdort / viewport.html
Last active May 30, 2021 16:28
Multiple viewports for Dummies
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.header {
background: #eee;
padding: 1rem;
display: flex;
@rmdort
rmdort / topological_sort_dag.ts
Last active May 30, 2021 16:27
Topologically sort (BFS) a DAG
/**
* Visit a graph node
* Sort it topologically and return
* all the dependents
* @param nodes
* @param previsit
* @returns
*/
const topologicalSort = <T>(nodes: T[], children: (node: T) => Set<T>) => {
const stack = new Set<T>();