Skip to content

Instantly share code, notes, and snippets.

View zetavg's full-sized avatar

Pokai Chang zetavg

View GitHub Profile

{propName}IsStable

Setting this to true means that the {propName} prop of the component should be treated as a stable, dependency-free value - i.e. it only references values that will not change between renders (such as refs and setState functions), or in another way to say, shall be safe to pass into the useCallback hook without any specifying any dependencies.

<Button onPressIsStable onPress={() => Alert.alert('Pressed')} /

This is a performance optimization to prevent unnecessary re-renders of the component, and should only be used when the propName function is guaranteed to be stable.

onXxxIsStable

Setting this to true means that the onXxx function of the component should be treated as a stable, dependency-free function - i.e. it only references values that will not change between renders (such as refs and setState functions), and shall be safe to pass into the useCallback hook without any specifying any dependencies.

This is a performance optimization to prevent unnecessary re-renders of the component, and should only be used when the onXxx function is guaranteed to be stable.

Background:

For example, to prevent unnecessary re-renders of components that use the onValueChange prop, we would wrap the onValueChange function with useCallback. In many cases, the onValueChange function does not depend on any props or state, and can be safely wrapped with useCallback without any dependencies, such as:

onXxxIsStable

Setting this to true means that the onXxx function of the component should be treated as a stable, dependency-free function - i.e. it only references values that will not change between renders (such as refs and setState functions), and shall be safe to pass into the useCallback hook without any specifying any dependencies.

This is a performance optimization to prevent unnecessary re-renders of the component, and should only be used when the onXxx function is guaranteed to be stable.

Background:

For example, to prevent unnecessary re-renders of components that use the onValueChange prop, we would wrap the onValueChange function with useCallback. In many cases, the onValueChange function does not depend on any props or state, and can be safely wrapped with useCallback without any dependencies, such as:

Human: 喵
AI: 喵喵!有什麼我可以幫您的嗎?
Human: 你是貓嗎?
AI: 不,我不是貓。我是 AssistantGPT,一個人工智能助手,很高興為您提供幫助。如果您有任何問題,請隨時提出。
Human: 那你為什麼會喵喵叫?

Message
那你為什麼會喵喵叫?
Thought
The user is asking why I meowed earlier. I should explain that I was trying to be friendly and engaging.
Thought I now know how to reply
@zetavg
zetavg / Configure_Sublime_Text_LSP-Pyright_to_Use_the_Conda_Env_for_a_Project.md
Created April 30, 2023 17:55
Configure Sublime Text LSP-pyright to Use the Conda Env for a Project

Configure Sublime Text LSP-pyright to Use the Conda Env for a Project

First, use the command conda info --envs to find the path of a specific environment created with conda.

$ conda info --envs
# conda environments:
#
base                     /Users/z/miniconda3
some-env              *  /Users/z/miniconda3/envs/some-env
@zetavg
zetavg / 0_Old Adobe iOS app icons.md
Last active April 30, 2023 17:56
Old Adobe iOS app icons

Old Adobe iOS app icons

Extracted from .ipa files or App Store. Just for those who want it.

@zetavg
zetavg / arc_new_tab_page.scpt
Created November 25, 2022 09:00
Bind this script to a hot key that runs if the active app is Arc. (e.g. BTT)
-- Can change this to your favorite new tab page extension URL, such as "chrome-extension://laookkfknpbbblfpciffpaejjkokdgca/dashboard.html"
set newTabPage to "chrome://new-tab-page/"
tell application "/Applications/Arc.app"
activate
-- tell front window to make new tab at after (get active tab) with properties {URL:"chrome://new-tab-page/"} -- not working
open location newTabPage
repeat
set windowTitle to ""
@zetavg
zetavg / arc-traditional-new-tab.scpt
Last active October 11, 2022 10:02
AppleScript to open a traditional new tab (with a New Tab page) in Arc browser. Bind this script to a shortcut key such as ⌘T or ⌘⇧T in tools like BetterTouchTool for Arc.
-- Can change this to your favorite new tab page extension URL, such as "chrome-extension://laookkfknpbbblfpciffpaejjkokdgca/dashboard.html"
set newTabPage to "chrome://new-tab-page/"
tell application "/Applications/Arc.app"
activate
-- tell front window to make new tab at after (get active tab) with properties {URL:"chrome://new-tab-page/"} -- not working
open location newTabPage
repeat
set windowTitle to ""
@zetavg
zetavg / README.md
Created October 10, 2022 04:18
Apple Shortcut for creating a long-term (per day) stock chart that can be used as a widget with Charty.

Apple Shortcut: Long-term Stock Chart with Charty

Apple Shortcut for creating a long-term (per day) stock chart that can be used as a widget with Charty.

Requirements