Skip to content

Instantly share code, notes, and snippets.

View DigitalZebra's full-sized avatar
🦓

Drew DigitalZebra

🦓
View GitHub Profile
@naqvitalha
naqvitalha / LazyScrollView.tsx
Created February 5, 2024 21:56
LazyScrollView
export const LazyScrollView = forwardRef(function LazyScrollView(
props: LazyScrollViewProps,
ref: ForwardedRef<FlashList<unknown[]>>,
): JSX.Element {
const {children, estimatedScrollViewSize, estimatedItemSize} =
props;
const data = isArray(children) ? children : Children.toArray(children);
// No specific reason for 2000, just a big number. Roughly 2x the screen size
@Cheesetouched
Cheesetouched / useOptimisticUpdate.js
Created September 24, 2023 08:36
Simple hook to perform optimistic updates with react-query
import { useCallback } from "react";
import { useQueryClient } from "@tanstack/react-query";
export default function useOptimisticUpdate() {
const queryClient = useQueryClient();
return useCallback(
async (queryKey, updater) => {
await queryClient.cancelQueries({ queryKey });
import Breakpoints from './Breakpoints';
import { css, cx } from '@emotion/css';
import { HTMLAttributes, forwardRef } from 'react';
export type StackProps = {
adaptive?: true;
alignCenter?: true;
center?: true;
children?: React.ReactNode;
className?: string;
@BalogunofAfrica
BalogunofAfrica / list-renderer.tsx
Created March 31, 2023 10:37
Simple API for using FlashList as Scrollview
import { FlashList, FlashListProps } from "@shopify/flash-list";
import React, { forwardRef, ReactElement } from "react";
type ListProps<T> = Omit<FlashListProps<T>, "children"> & { as?: "list" };
type ScrollViewProps<T> = Omit<
FlashListProps<T>,
"children" | "data" | "renderItem"
> & {
as?: "scroll-view";
children: React.ReactNode | React.ReactNode[];
@EvanBacon
EvanBacon / expo-vscode-settings.json
Created February 14, 2023 18:33
Expo file nesting patterns. Ensure all related extensions are nested inside of the default file.
{
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.js": "${capture}.js.map, ${capture}.d.ts, ${capture}.d.ts.map",
"*.ts": "$(capture).test.ts, $(capture).test.tsx, $(capture).test.node.ts, $(capture).test.node.tsx, $(capture).test.native.ts, $(capture).test.native.tsx, $(capture).test.ios.ts, $(capture).test.ios.tsx, $(capture).test.web.ts, $(capture).test.web.tsx, $(capture).test.android.ts, $(capture).test.android.tsx, ${capture}.native.tsx, ${capture}.ios.tsx, ${capture}.android.tsx, ${capture}.web.tsx, ${capture}.native.ts, ${capture}.ios.ts, ${capture}.android.ts, ${capture}.web.ts, ${capture}.native.js, ${capture}.ios.js, ${capture}.android.js, ${capture}.web.js, ${capture}.native.jsx, ${capture}.ios.jsx, ${capture}.android.jsx, ${capture}.web.jsx",
"*.tsx": "$(capture).test.ts, $(capture).test.tsx, $(capture).test.node.ts, $(capture).test.node.tsx, $(capture).test.native.ts, $(capture).test.native.tsx, $(capture).test.ios.ts, $(capture).test.ios.tsx, $(captur
function Favorite({
postId = null,
isLiked: _isLiked = false,
numberOfLikes: _numberOfLikes = 0,
}) {
const [isLiked, setIsLiked] = React.useState(_isLiked);
const [numberOfLikes, setNumberOfLikes] = React.useState(_numberOfLikes ?? 0);
const likeDebounceRef = React.useRef();
const lastIsLikedStateRef = React.useRef(_isLiked);
import UIKit
import SwiftUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let box = UIView()
box.frame = CGRect(x: (view.bounds.width / 2.0) - 100.0, y: 0.0, width: 100.0, height: 100.0)
box.backgroundColor = .systemGreen
@TheEhsanSarshar
TheEhsanSarshar / ReactNativeResponsiveUtilities.ts
Last active September 1, 2022 11:36
React Native Responsive Utility Functions
import { Dimensions } from 'react-native';
const { height: screenHeight, width: screenWidth } = Dimensions.get('window');
const EACH_HEIGHT_UNIT = screenHeight / 100
const EACH_WIDTH_UNIT = screenWidth / 100
/**
* device height percentage
*/
import UIKit
import AVFoundation
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let tableView = UITableView(frame: .zero, style: .plain)
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(PlayerTableViewCell.self, forCellReuseIdentifier: "PlayerCell")
import UIKit
class ViewController: UIViewController {
let textViewWrapper = TextViewWrapper()
override func viewDidLoad() {
super.viewDidLoad()
// The problem view! I want to add this one to my set of Auto Layout constraints,
// even though it's not using Auto Layout internally.