Posts categorized as code

Concatenate multiple optional items with separators
Concatenating strings is a pretty straight forward task in JavaScript and with the introduction of template literals with string interpolation things got even simpler. Let's say that we want to concat a couple of inputs of a form that is…
Update state with useReducer synchronously
Hooks in Reacts are wonderful to work with and managing local state is one of the most common ones. For more complex states the useState() hook could be changed to a useReducer() instead. A problem we might encounter is that state isn't…
Partial types in TypeScript
TypeScript is great for many reasons and when getting past the first few steps it really makes developing a joy. With that said there may come a time when objects keep growing in size and maybe not all properties will exist all the time…
Conditions in CSS with the :not pseudo class
When writing CSS we sometimes want some more logic to our styling. For example a navigation with multiple elements in a horizontal layout probably needs some space between the elements. A padding-right could do it but we don't want…
Put GraphQL fragments in their own files in Gatsby
Gatsby uses GraphQL under the hood for managing data and it does this really well. It usually doesn't take long before the queries grow big and some duplicated code will occur. This is where fragments come in handy. A way to break out…

All categories