Skip to content

Instantly share code, notes, and snippets.

View paraparata's full-sized avatar
🏠
Remote

zal paraparata

🏠
Remote
View GitHub Profile
#/bin/sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" && \
brew install --cask frappe-books
@paraparata
paraparata / localStorageCreator.ts
Created December 2, 2023 08:47
A helper to create stateful localStorage in React
import { useSyncExternalStore } from 'react';
type Selector<T, R> = (prev: T) => R;
type UseStore<T, M> = {
<R>(selector: Selector<T | null, R>): R;
} & M;
/**
* A helper to create stateful localStorage.
@paraparata
paraparata / contextCreator.tsx
Created December 2, 2023 08:20
A helper to generate React context.
import { createContext, useContext, useMemo, useState } from 'react';
/**
* A helper to generate React context.
*
* @returns A tuple of context provider and context hook
*
* @example
* // Initialize outside component. Generic type required as context value type.
* const [SearchBarProvider, useSearchBar] = contextCreator<string>();
@paraparata
paraparata / 00-README-NEXT-SPA.md
Created March 18, 2023 14:10 — forked from gaearon/00-README-NEXT-SPA.md
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.

You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.

You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)

Building

type ControlledElement =
| HTMLInputElement
| HTMLTextAreaElement
| HTMLSelectElement;
/**
* Native setter for controlled element (e.g. `input`, `textarea` and `select`) that mimic real user.
* Reference from
* [here](https://hustle.bizongo.in/simulate-react-on-change-on-controlled-components-baa336920e04)
*/
@paraparata
paraparata / waitForEl.ts
Created December 9, 2022 09:43
Waiting for element to query
/**
* Async to monitor changing state on element (e.g. <button> based on disable attribute)
*/
export const waitForElState = async <T extends Element | null>(
selector: string,
parent: Element | Document,
validator: (mutations: MutationRecord[]) => boolean,
callback: () => void,
options?: Partial<MutationObserverInit>
): Promise<T> => {
const Input = React.forwardRef((props, ref) => {
const {
type,
currency,
telOptions,
label,
className,
disabled = false,
prefix,
suffix,
@paraparata
paraparata / lkzndev-launcher.html
Created October 3, 2021 12:01
LKZNDEV Welcoming Screen 9:16
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LKZNDEV</title>
<style>