Bruno Sabot
brunosabot.bsky.social
Bruno Sabot
@brunosabot.bsky.social
12 followers 34 following 500 posts
Posts Media Videos Starter Packs
`useWhyDidYouUpdate("MyComponent", props);`

This hook will let you know from the console the attributes of an object that have been updated, causing rerendering.

You should use it to avoid unnecessary renders.

#techtweets #day200
When writing JavaScript, you should always pick functions over classes.

For the same result, the code generated by Babel with be smaller with functions.

#techtweets #day199
You can use intersection types to extends an existing TypeScript type.

It is useful to reuse and factorize some pieces of definitions.

#techtweets #day198
With ECMAScript 2022, JavaScript now has private fields in classes.

You need to prefix an attribute or a method with # to make it private.

#techtweets #day197
`git config --global --add --bool push.autoSetupRemote true`, starting Git 2.37.0, will automatically set the up the upstream branch, and will save you from `git push --set-upstream origin feat/awesome-feature`

#techtweets #day196
The object-fit CSS property will keep your image with a good ratio and the box will either contain the image perfectly or crop it.

#techtweets #day195
High order component add a generic behavior to a component.

It can be helpful to wrap an element with a descriptive tooltip.

#techtweets #day194
You can load polyfills with the `nomodule` attribute: modern browser will ignore the script while old will not understand the `nomodule` attribute.

#techtweets #day193
To create truly readonly objects in TypeScript, you can use the `as const` suffix to a variable declaration.

Any property or sub-property will then become readonly.

#techtweets #day192
The padStart and padEnd functions are adding a specific character at the start or the end of your string to reach a specific string length.

#techtweets #day191
Get the current branch name of a git repository in a single command: `git rev-parse --abbrev-ref HEAD`

It can give you superpowers when creating a shell script.

#techtweets #day190
With the CSS aspect-ratio, you can define the size of an element without knowing about the final rendered width of your element.

It might help you avoid layout shifts

#techtweets #day189
`setInterval` is not directly compatible with React, as it needs to match start and stop with a component mounting and unmounting.

The hook that solves that uses refs and effects to manage the interval correctly.

#techtweets #day188
With facades, you can improve your page performances: by loading a lite version of a third party script -such as YouTube, Twitter, and more-, you can lower the initial load time of the page.

Learn more on#techtweets #day187

web.dev/third-party-fa…
Lazy load third-party resources with facades  |  Lighthouse  |  Chrome for Developers
Learn about the opportunities to lazy load third-party resources with facades.
web.dev
Did you know that you can group your TypeScript code inside namespaces?

It will act like an object, but it will also merge multiple definitions if included in the same namespace

#techtweets #day186
There is a `showPicker()` method on HTML `` elements that can open the detailed view for `date`, `month`, `week`, `time`, `datetime-local`, `color`, and `file` types.

This can also be triggered for ``.

#techtweets #day185
Find files (and lines) where a specific text is in tracked files with git grep:

`git grep --heading --line-number 'text to find'`

--heading will group lines by file
--line-number (or -n) will show... line numbers.

#techtweets #day184
With today's tweet, I'm officially starting the second half of the tech tweets year: 183 done, 182 to go.

It's getting harder to find new topics, so I hope you still like the content!
The CSS order property allow you to display items in a different order.

It is very helpful on responsive designs or to priorise the right information for screen readers -a title is more important than an image.

Use it with care however.

#techtweets #day183
The useKeyPress hook returns true when a specific key is pressed.

`const forward = useKeyPress("w");`

You might want to use it for a `wasd` navigation for example.

#techtweets #day182
Typescript decorators are a simple way to apply an high order function on a method or a class.

It can be used to measure a method's performance or inject additional parameters among many other use cases.

#techtweets #day180