Kyle Shevlin

Software Engineer

Snippets

Inspired by Josh W. Comeau's blog, this is a collection of my code snippets that you can look at for inspiration or copy/paste at will.

NameDescriptionCategory
clamp()Description:
A function that "clamps" a number between a minimum and maximum value
Category: JavaScript
compose() & pipe()Description:
Functions for composing other functions
Category: JavaScript
indexByKey()Description:
A function to turn an array of objects into an object, indexed by the chosen key
Category: JavaScript
inflect()Description:
Function used to choose the correct form of a word, singular or plural
Category: JavaScript
partition()Description:
Split an array with a predicate filter
Category: JavaScript
randomRGB()Description:
Function to generate random rgb() strings
Category: JavaScript
SpacerDescription:
A component for easily applying margins with component composition
Category: React Component
toArray()Description:
A function for normalizing a value to an array
Category: JavaScript
useForceUpdate()Description:
An imperative way to force a component to update with Hooks
Category: React Hooks
useLocalStorage()Description:
Hook for persisting state to localStorage
Category: React Hooks
usePrevious()Description:
Hook for storing and getting a previous value
Category: React Hooks
useSwitch()Description:
A basic React Hook for managing binary states
Category: React Hooks

Let's talk some more about JavaScript, React, and software engineering.

I write a newsletter to share my thoughts and the projects I'm working on. I would love for you to join the conversation. You can unsubscribe at any time.

Introduction to State Machines and XState Logo
Introduction to State Machines and XState

Check out my courses!

Liked the post? You might like my courses, too. Click the button to view this course or go to Courses for more information.
I would like give thanks to those who have contributed fixes and updates to this blog. If you see something that needs some love, you can join them. This blog is open sourced at https://github.com/kyleshevlin/blog
alexloudenjacobwsmithbryndymentJacobMGEvanseclectic-codingjhsukgcreativeerikvorhesHaroenvmarktnoonandependabotmarcuslyonsbrentmclarkfederico-fiorinimedayzDoNormal
©2021 Kyle Shevlin. All Rights Reserved.