Skip to content

Instantly share code, notes, and snippets.

View hungify's full-sized avatar
🎯
Focusing

hungify hungify

🎯
Focusing
  • ˋ@2024ˎˊ
  • undefined, Vietnam
  • 15:12 (UTC +07:00)
View GitHub Profile
@hungify
hungify / react.md
Last active May 15, 2024 15:49
Summary about React Ecosystem

Summary

  • React always recursively renders components by default, so when a parent renders, its children will render
  • Rendering by itself is fine - it's how React knows what DOM changes are needed
  • But, rendering takes time, and "wasted renders" where the UI output didn't change can add up
  • It's okay to pass down new references like callback functions and objects most of the time APIs like React.memo() can skip unnecessary renders if props haven't changed
  • But if you always pass new references down as props, React.memo() can never skip a render, so you may need to memoize those values
  • Context makes values accessible to any deeply nested component that is interested
  • Context providers compare their value by reference to know if it's changed
  • A new context values does force all nested consumers to re-render but, many times the child would have re-rendered anyway due to the normal parent->child render cascade process
@hungify
hungify / refresh-token-machine.tsx
Last active May 12, 2024 08:21
Refresh Token Machine (X Time before expiration)
"use client";
import dayjs from "dayjs";
import { jwtDecode } from "jwt-decode";
import { useRouter } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { useAuthContext } from "../auth/context";
export default function RefreshTokenMachine() {
const [diff, setDiff] = useState<number>(1000);
@hungify
hungify / keymap.json
Last active February 15, 2024 06:31
My Zed keymap Settings
[
// Bindings from VS Code
{
"context": "Editor",
"bindings": {
"cmd-shift-k": "editor::DeleteLine",
"cmd-i": "editor::ShowCompletions",
"alt-up": "editor::MoveLineUp",
"alt-down": "editor::MoveLineDown",
"alt-shift-down": "editor::DuplicateLine", // alt is option
@hungify
hungify / settings.json
Last active February 24, 2024 13:14
My Zed Settings
{
"extend_comment_on_newline": false,
"format_on_save": "on",
"theme": "Ayu Mirage",
"formatter": "auto",
"buffer_font_family": "Monaspace Neon",
"buffer_font_features": {
"calt": true,
"liga": true,
"dlig": true,
@hungify
hungify / alpine_cron_job.md
Last active December 3, 2023 09:40
Running cron job inside a Docker container with Alpine distribution.

Running cron job inside a Docker container with Alpine distribution

With Docker

alpine.dockerfile

FROM alpine

RUN which crond && rm -rf /etc/periodic