You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for a row layout with different gaps between rows when CSS gap cannot be used, applying margin-top to each element, starting from the second one, is the best approach. Following this method consistently makes layouts more predictable and easier to manage.
Avoid creating separate files and exports for tiny, internal helper components that only serve to build a single larger parent component.
Example: In LiveStats.tsx, components like LiveStatContainer, LiveStatTitle, and LiveStatValue are only used to compose LiveStats. Keeping them as local functions inside the same file clarifies their scope and keeps the file structure clean.
Rules of Thumb for when to create a separate file:
Reusability: The component is used in multiple different parent components across the app.
Complexity: The component has its own complex state, logic, or dedicated hooks.
File Size: The parent file grows too large (e.g., exceeding 150-200 lines), signaling a need to break things up.
I was familiar with React's <Fragment>. and it's short hand which is written like <>. and I always used the short hand, although some places the <Fragment> is more useful. like where? where in a list of components you return and want to add "Key" prop to the fragment. you can't add key to the short hand version but you can add it to the <Fragment>. so use it sometimes.
Learned how and when to use the third parameter of React's useReducer hook. This optional parameter is a function called the initializer function. When omitted, the initial state is simply the second parameter (initialArg). However, when defined, React runs init(initialArg) to determine the initial state. This is especially useful when we have an initial state in mind but want to change or transform it somehow before actually assigning it to our reducer state (i.e. performing lazy initialization), keeping our setup clean and organized.
When disabling native clickable elements like <button>, using the HTML disabled attribute is the standard, semantic, and highly preferred approach over CSS pointer-events: none.
Avoid calling Math.random() directly within a component's render body. Instead, use useState with a lazy initializer function to safely generate and persist a random value when the component mounts.
padStart method on strings in javascript lets you add a repeating string to the called string until it reaches a certain length. helps formatting strings.
Instead of defining text typography classes inside @layer components (which stay as static component styles), bundling them with @utility turns them into first-class Tailwind utilities. This unlocks Tailwind variant modifiers (like sm:, hover:, dark:) so they can be combined responsively directly in JSX.