Skip to content

Instantly share code, notes, and snippets.

@JacobJaffe
JacobJaffe / BlurScrollExample.tsx
Created November 28, 2024 01:17
ScrollView with BlurView header / footer
const BlurScrollTestScreen = () => {
const insets = useSafeAreaInsets();
const [refreshing, setRefreshing] = useState(false);
const refresh = async () => {
setRefreshing(true);
setTimeout(() => {
setRefreshing(false);
}, 3000);
type PluralOptions = {
pluralForm?: string;
};
export const formatPlural = (
noun: string,
count: number,
options: PluralOptions = {}
) => {
return `${count} ${pluralize(noun, count, options)}`;
import { useState, useRef, useEffect } from "react";
// For wrapping state that is frequently updated, but used for an api,
// e.g. a text input hooked up to a search query.
export function useDebouncedTrigger<T>(trigger: T): T {
const [debouncedTrigger, setDebouncedTrigger] = useState(trigger);
const _timeout = useRef<NodeJS.Timeout | null>(null);
useEffect(() => {
@JacobJaffe
JacobJaffe / createMappedStyle.ts
Created February 8, 2022 23:56
React Native Mapped Style Generation
import { StyleSheet, ViewStyle } from "react-native";
type ValueOf<T> = T[keyof T];
type mapFunc<V extends ValueOf<ViewStyle>> = (
key: string,
value: V
) => ViewStyle;
/**
@JacobJaffe
JacobJaffe / useLoadingAnimation.tsx
Created January 17, 2022 23:38
React Native loading animation easy hook
import { useState, useEffect, useRef } from "react";
import { LayoutAnimation } from "react-native";
/import { useState, useEffect, useRef } from "react";
import { LayoutAnimation } from "react-native";
/**
*
* Triggers a layout animation when the loading parameter changes.
import { useRef, useEffect } from "react";
/**
* Returns a boolean ref to determine if the component is still mounted.
* Useful for (stopping) async logic that can't occur after a dismount.
*/
export const useIsMounted = () => {
const mounted = useRef(true);
useEffect(
() => () => {