- 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
// Bindings from VS Code | |
{ | |
"context": "Editor", | |
"bindings": { | |
"cmd-shift-k": "editor::DeleteLine", | |
"cmd-i": "editor::ShowCompletions", | |
"shift-pageup": "editor::SelectToBeginning", | |
"shift-pagedown": "editor::SelectToEnd", | |
"cmd-pageup": "editor::PageUp", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"assistant": { | |
"default_model": { | |
"provider": "copilot_chat", | |
"model": "gpt-4o" | |
}, | |
"version": "2" | |
}, | |
"terminal": { | |
"cursor_shape": "bar" |