Snippets

Little bits of code that I find useful and you might too! Mostly written in TypeScript (with a transpiled JavaScript version available) and often for React and SolidJS.

Tailwind CSS Hocus Plugin
A plugin for lazy people like me who use the same styles for hover and focus states
09/19/22
09/22/22
Stop Vercel GitHub Comments
Stop Vercel's bot from commenting on PRs and commits (and the associated emails)
08/27/22
09/25/22
useIsMouseInactive (SolidJS)
Know when the mouse hasn't moved for a period of time
08/27/22
09/03/22
useSyncedLocalStorage (React)
Save state to localStorage and sync it between hook instances, tabs and windows!
07/07/22
09/14/22
useCssVar (React)
Control a css variable from the comfort of React.
05/04/22
09/14/22
useCopy (React)
Copy to clipboard with a 'copied' timeout
05/02/22
useCopy (SolidJS)
Copy to clipboard with a 'copied' timeout
05/02/22
08/27/22
File Downloads
Download a file with or without JavaScript
04/26/22
09/03/22
Enzyme Stuff
Miscellaneous snippets for working if you have to do tests with Enzyme
02/20/22
PartiallyRequired
A TypeScript type to make part of another type not optional.
10/28/21
cx
A tiny helper function to conditionally join classnames.
05/09/21
09/03/22
useBoolean (React)
Toggle and set a boolean piece of state with a slightly better interface than straight useState
05/02/21
09/14/22
Next.js <Redirect />
A <Redirect /> component like the one for react-router.
04/02/21
09/03/22
useMounted (React)
Know when the current component is mounted.
04/02/21
09/14/22
debounce
Run a function at most once every N seconds, at the end of the N seconds.
03/28/21
throttle
Run a function at most once every N seconds, at the start of the N seconds.
03/28/21
useLocalStorage (React)
Save state to localStorage with an interface almost identical to useState
03/26/21
09/14/22
Hello World
Show "Hello, World!" to your screen.
03/24/21
09/07/22
18 snippets total

License for these snippets

License

If you want, you can (and probably should) include the entire license below. I'm not a lawyer, though so idrk.

MIT License Copyright (c) 2022 Soorria Saruva

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.