ClarityDev blog | RSS Feed
https://claritydev.net
Front-end web developer. Based in Helsinki, Finland.
フィード
Testing React Hook Form With React Testing Library
ClarityDev blog | RSS Feed
React Hook Form has emerged as a popular and efficient library for managing form state and validation in React applications. It simplifies handling form inputs, reduces boilerplate code, and provides a performant solution for form management. However, testing these forms efficiently and accurately is just as important as implementing them.
9ヶ月前
Managing forms with React Hook Form
ClarityDev blog | RSS Feed
Working with forms in React is notoriously difficult, particularly when there are dynamic fields involved. There exist several libraries that make the whole process easier. One such library is React Hook Form. In this post, we talk about the basics of React Hook Form and learn how to use it to simplify form management in your React applications.
9ヶ月前
Intersection Types in TypeScript
ClarityDev blog | RSS Feed
Intersection types provide a way of combining multiple types into one, enabling the creation of sophisticated type systems that can enhance the development workflow and maintainability of the code. This post explores the basics of intersection types in TypeScript and how they can be used to create more robust type systems.
9ヶ月前
Working with Union Types in TypeScript
ClarityDev blog | RSS Feed
Union types in TypeScript offer a versatile way to define variables and functions that are intended to handle more than a single data type. This post will demonstrate how union types wor in TypeScript and will touch upon their declaration, usage in functions, and practical examples.
9ヶ月前
Best Practices for Writing Tests with React Testing Library
ClarityDev blog | RSS Feed
Properly written tests not only help prevent regressions and buggy code, but in the case of React Testing Library, they also improve the accessibility of components and the overall user experience. In this post, we'll explore how to get the most out of your React Testing Library tests. I'll provide a collection of what I consider to be best practices and tips on how to avoid common mistakes with React Testing Library.
9ヶ月前
Mastering JavaScript Array Sorting: Array.prototype.sort() with Examples
ClarityDev blog | RSS Feed
Explore the Array.prototype.sort() method in JavaScript, learning how to handle various sorting scenarios, combine multiple sorting criteria, and manage limitations and caveats for effective array sorting in your applications.
9ヶ月前
Immutable Array Operations in JavaScript: Introducing toSorted, toSpliced, and toReversed
ClarityDev blog | RSS Feed
This blog post explores the new immutable array methods, such as Array.prototype.toSorted, Array.prototype.toSpliced, and Array.prototype.toReversed.
9ヶ月前
Higher-Order Functions in JavaScript
ClarityDev blog | RSS Feed
Higher-order functions are a powerful feature in JavaScript that enable the abstraction of control flows and data operations. This article explores the concept of higher-order functions, providing examples of their use in everyday coding.
10ヶ月前
Understanding and Implementing Type Guards in TypeScript
ClarityDev blog | RSS Feed
Type guards are a powerful feature in TypeScript that allows you to narrow down the type of an object within a certain scope. With type guards, you can perform specific checks to determine the type of an object and then use that object in a way that is type-safe according to the TypeScript compiler. In this post, we'll look into the concept of type guards, explore the different types of type guards that TypeScript offers, and learn how to use them in practical scenarios.
10ヶ月前
Creating Accessible Form Components with React
ClarityDev blog | RSS Feed
Learn how to create accessible form components with React to ensure that all users, including those with disabilities, can interact with your web applications.
10ヶ月前
Beyond console.log: Debugging techniques in JavaScript
ClarityDev blog | RSS Feed
Learn about alternative debugging techniques in JavaScript that can help you become a more efficient and effective developer.
10ヶ月前
TypeScript's Infer Keyword: Unlocking Type Information
ClarityDev blog | RSS Feed
TypeScript's infer keyword is a powerful tool for extracting type information from other types. In this article, we'll explore how to use it to create more flexible and reusable type definitions.
10ヶ月前
Getting Started with Template Literals in JavaScript
ClarityDev blog | RSS Feed
Template literals in JavaScript have reshaped the creation and usage of strings. This article provides an overview of template literals, explores advanced usage and features, discusses real-world applications, and outlines best practices for their effective use.
10ヶ月前
Add Dynamic Sitemap to Next.js Website Using Pages or App Directory
ClarityDev blog | RSS Feed
In this post we will explore how to add a dynamic sitemap to a Next.js website using both the 'pages' and 'app' directories. A sitemap is a file that lists all the pages of a website and helps search engines understand the structure of the site. By the end of this post, you will have a fully functional dynamic sitemap for your Next.js website.
10ヶ月前
Introduction to Type Inference in TypeScript
ClarityDev blog | RSS Feed
Type inference in TypeScript helps in determining variable or expression types based on its value when it's not explicitly specified. When TypeScript can infer the type of a variable, there is no need to annotate the variable with a type, which can make the code cleaner and easier to read.
10ヶ月前
TypeScript Advanced Types: Working with conditional types
ClarityDev blog | RSS Feed
In this blog post, we'll look at conditional types, exploring how they work, where they are most effective, and some of the advanced patterns they enable. We'll also discuss best practices for using conditional types and consider their limitations.
10ヶ月前
Error Handling and Defensive Programming with TypeScript
ClarityDev blog | RSS Feed
Learn how to handle errors and write more resilient code with TypeScript's type system and advanced features. Explore common error types, exception handling, defensive programming, and advanced error handling patterns.
10ヶ月前
Unlocking the Power of TypeScript's Mapped Types
ClarityDev blog | RSS Feed
Mapped types in TypeScript are a powerful tool for creating new types based on existing ones. This post explores the core concepts of mapped types and demonstrates advanced use cases and best practices for working with them.
10ヶ月前
Simplifying Form Rendering in React with Field Component Abstraction
ClarityDev blog | RSS Feed
Learn how to simplify form rendering in React by abstracting the field rendering logic into a reusable component.
10ヶ月前
Understanding Controlled vs uncontrolled components in React
ClarityDev blog | RSS Feed
Controlled and uncontrolled components are fundamental concepts in React. This post explains the differences between the two and provides guidelines for choosing the right approach for various scenarios in React applications. We'll also explore how to transition between the two types of components and provide code examples to illustrate the concepts.
10ヶ月前
Build a Multistep Form With React Hook Form
ClarityDev blog | RSS Feed
Multistep forms a.k.a. wizard or funnel forms have a wide range of uses. They are most common when collecting different types of information into one data structure but are also useful to break down very large forms into the less user-intimidating multistep process. In this post, we'll build a basic multistep registration form, which collects the user's info and then presents it in a confirmation view, which can be reviewed and edited before the submission.
10ヶ月前
Using Generics in TypeScript: A Practical Guide
ClarityDev blog | RSS Feed
Generics in TypeScript are a powerful feature that, when used effectively, can greatly enhance your code's flexibility, reusability, and safety. By understanding their practical applications, mastering advanced techniques, and adhering to best practices, you will be well-equipped to harness the full potential of generics in your TypeScript projects.
10ヶ月前
React Hook Form: Working with multipart form data and file uploads
ClarityDev blog | RSS Feed
Learn how to handle file uploads and multipart form data in React applications using React Hook Form. This tutorial demonstrates adding file input fields, working with FormData API, and submitting form data.
10ヶ月前
Build Dynamic Forms with React Hook Form
ClarityDev blog | RSS Feed
Discover how to efficiently create scalable and maintainable dynamic forms for various configurations using React Hook Form. This guide explores practical strategies and code examples for rendering flexible form controls with streamlined validation in React applications.
1年前
Continuously Deploying Next.js website to DigitalOcean using GitHub Actions
ClarityDev blog | RSS Feed
In this post, we'll dive into the automation of a Next.js website deployment to DigitalOcean using GitHub Actions. We'll discuss what GitHub Actions are and how they can be utilized to continuously deploy modifications to a remote server. This approach reduces the requirement for manual intervention and minimizes downtime. By the conclusion of this post, you'll have a robust understanding of how to automate your deployment workflow and achieve faster, more reliable deployments with ease.
1年前
Build a Tic-Tac-Toe game with TypeScript, React and Minimax
ClarityDev blog | RSS Feed
In this tutorial, we will build a Tic-Tac-Toe game with TypeScript, React, React Hooks, and style it using the Styled Components library. Additionally, we'll use the Minimax algorithm to power the AI moves. The final code is available on both GitHub and CodeSandbox.
1年前
Form Validation with React Hook Form
ClarityDev blog | RSS Feed
Form validation is the process of checking the entered data against specific criteria before it is processed. This can include checking that a required field has been filled out, that an email address is in the correct format, or that a password meets specific complexity requirements. Among the numerous tools and libraries available for form validation in React, React Hook Form stands out as a robust, easy-to-use solution.
1年前
Drag-and-Drop File Upload Component with React and TypeScript
ClarityDev blog | RSS Feed
In this tutorial we'll walk through the steps required to build a file upload component in React, using TypeScript for additional type safety and robustness. The unique aspect of our approach is that we won't rely on any external libraries, giving you the fundamental knowledge and freedom to create and customize a file upload solution that fits your specific needs.
1年前
TypeScript Template Literal Types: Practical Use-Cases for Improved Code Quality
ClarityDev blog | RSS Feed
Explore practical use-cases of TypeScript template literal types to enhance code safety and maintainability. Learn to leverage advanced type features for more expressive, robust, and easy-to-manage applications.
1年前
Advanced String Manipulation with Tagged Templates in JavaScript
ClarityDev blog | RSS Feed
In this blog post, we will explore the basics of template literals and various use cases where they prove to be particularly useful. Then we'll dive into a more advanced form called tagged templates, which provide even greater control over string construction. By the end of this post, you'll have a solid understanding of how to leverage tagged templates for advanced string manipulation in your JavaScript code.
2年前
Diacritic-insensitive string comparison in JavaScript
ClarityDev blog | RSS Feed
This post discusses the diacritic-insensitive string comparisons in JavaScript. Learn how to enhance your array filtering by normalizing strings, understand the nuances of Unicode characters, and explore practical considerations and potential performance impacts of this approach.
2年前
Mocking the window object in Jest tests
ClarityDev blog | RSS Feed
In this article, we'll explore the best practices for mocking the window object in Jest, using a simple function that retrieves a language code from a page URL as an example.
2年前
Typing React context in TypeScript
ClarityDev blog | RSS Feed
In this article, we'll see how to type React context in TypeScript. We explore the process of creating a theme context supporting dark and light themes, addressing type-related challenges along the way.
2年前
Testing Select components with React Testing Library
ClarityDev blog | RSS Feed
Learn how to test Select components with React Testing Library, including native selects, synchronous and asynchronous react-select components, and best practices for accessibility. Explore code examples and tips for testing custom select components in React.
2年前
What is NaN: A deeper dive into JavaScript's implementation of the IEEE-754 floating point standard
ClarityDev blog | RSS Feed
NaN, or 'Not a Number', is a special value in JavaScript and TypeScript (as well as many other programming languages) that represents an undefined or unrepresentable value resulting from an arithmetic operation. It is often used as a placeholder for a missing numerical value or as a way to signify an error. However, what is the type of NaN in JavaScript?
2年前
Productivity Benefits of Integrating ChatGPT into the Front-End Development Process
ClarityDev blog | RSS Feed
Boost your web development productivity with ChatGPT. Learn how to leverage its features for code generation, debugging, optimization, and more in TypeScript and JavaScript projects.
2年前
Display Warning for Unsaved Form Data on Page Exit
ClarityDev blog | RSS Feed
This article shows how to implement a FormPrompt component that alerts users when they attempt to leave a page with unsaved changes. It discusses handling such scenarios using pure JavaScript with the beforeunload event, as well as React-specific solutions using the Prompt component in React Router v5 and the useBeforeUnload and unstable_useBlocker hooks in React Router v6.
2年前
Advanced Multistep Forms with React Hook Form
ClarityDev blog | RSS Feed
In a previous post, we built a basic multistep registration form using React and React Hook Form. In this article, we'll expand upon that foundation by implementing improvements, such as enabling data saving during step navigation and enhancing the visual representation of each step's state.
2年前
The most common mistakes when using React
ClarityDev blog | RSS Feed
Discover common React mistakes that developers make when using hooks, managing state, and rendering components. Learn how to identify and fix these mistakes to improve your application's performance and maintainability.
2年前
Tips on becoming a self-taught developer
ClarityDev blog | RSS Feed
Lately, I have been asked increasingly often for some tips on how to become a self-taught developer, so I thought I'd write a post about it, reflecting on my experience and pointing out the things I'd do differently. In this article, I'll try to give general advice on how to improve for those considering or maybe already on the way to becoming self-taught software developers. It should be noted that the focus of the post is on front-end development since that's what I did; however, a majority of the advice can be applied to becoming a software engineer, irrespective of focus.
2年前
Simplifying Connected Props with Redux and TypeScript
ClarityDev blog | RSS Feed
Learn how to simplify connected props with Redux and TypeScript by using the ConnectedProps helper type. In this article, we'll walk through a concrete example and show you how to automatically infer the types of connected props from mapStateToProps and mapDispatchToProps. This will help you avoid manual type declaration and improve the maintainability of your app.
2年前
Add a blog to your Django website
ClarityDev blog | RSS Feed
Learn how to seamlessly integrate a fully functional and customizable blog into your existing Django website with this step-by-step tutorial, covering CRUD functionality, views, templates, and more.
2年前
TypeScript: Typing form events in React
ClarityDev blog | RSS Feed
Handling events in React is very close to how the events on DOM elements are handled. The biggest difference is, however, that React wraps the native DOM events into SyntheticEvent, making them behave slightly differently than the native events. Consequently, typing form events in React is not the same as native events. In this post, we'll see how to type form events in React on the example of a simple component as well as discuss the most common pitfalls.
2年前
TypeScript: Typing React useRef hook
ClarityDev blog | RSS Feed
Discover how to effectively type the useRef hook in TypeScript for React applications that require imperative DOM manipulation. Learn best practices, common pitfalls, and practical examples, such as controlling the focus state of an input element.
2年前
Removing duplicates with Map in JavaScript
ClarityDev blog | RSS Feed
Removing duplicate items from an array using Set is a common practice in JavaScript. However, what's less well-known is that the Map data structure can also be used for this purpose. The reason is that Map maintains key uniqueness, which means that there can't be more than one key-value pair with the same key.
2年前
Simplifying code with Maps in JavaScript and React
ClarityDev blog | RSS Feed
The Map data structure is a relatively lesser-known addition of ES6 to the JavaScript language. It offers several advantages over objects, particularly when it comes to storing collections of key-value pairs. One interesting use case of Map is simplifying React components that render different JSX based on frequently changing state variables.
2年前
Testing Firestore locally with Firebase emulators
ClarityDev blog | RSS Feed
Running Firestore operations on a local database is an essential aspect of efficient Firebase development. In this tutorial, we'll guide you through the process of setting up and testing Firestore operations using a Firestore local database with the help of Firebase Emulator.
2年前
Create an interactive table of contents for a Next.js blog with Remark
ClarityDev blog | RSS Feed
A well-organized and easily navigable table of contents significantly enhances the user experience, simplifying the process for readers to find the information they need. In this post, we'll go through the necessary steps to create an interactive table of contents for a Next.js blog using Remark, a powerful Markdown processor.
2年前
Optimize Redux Development: Simplify Boilerplate Creation with Code Generators and Plop.js
ClarityDev blog | RSS Feed
Many developers seek ways to simplify their Redux development workflow and improve efficiency. In this article, we'll explore how to speed up your Redux development by automating the process of scaffolding boilerplate code with Plop.js code generators. We'll cover the best practices for using Plop.js in your Redux projects, how it can help you reduce boilerplate, and streamline your development process.
2年前
Speed up your React developer workflow with Plop.js code generators
ClarityDev blog | RSS Feed
As React developers, we often find ourselves setting up new components, connecting them with the existing infrastructure, or scaffolding applications. That's a lot of repetitive manual work, which even though doesn't happen that often, can be quite tedious and frankly, boring. Fortunately, there is a solution that can help us to automate this process and save time: JavaScript code generators.
2年前
Copy to clipboard button in MDX with Next.js and Rehype Pretty Code
ClarityDev blog | RSS Feed
This tutorial will guide you on how to create a 'copy to clipboard' button for the code snippets processed with Rehype Pretty Code plugin for syntax highlighting in Next.js. We'll be using Next.js 13+ with the 'app' directory enabled. By the end of this post, you'll be able to streamline code sharing and enhance the user experience on your Next.js website. In fact, this blog uses the exact functionality we'll be creating, so you can see the end result in action.
2年前
Enzyme vs React Testing Library: A migration guide
ClarityDev blog | RSS Feed
This blog post provides a basic comparison of both libraries and presents a migration guide based on code samples from each library. We'll write tests for the Tic-Tac-Toe game from an earlier post using Enzyme and then transform them into React Testing Library tests.
2年前
Building component library with Docz and Lerna
ClarityDev blog | RSS Feed
Component libraries are all the rage these days, with many companies rolling out their own solutions or sticking to a bunch of open source alternatives. Leveraging a component library for UI development, particularly in large teams, has a lot of cool benefits. It allows to take full advantage of modular and reusable UI components, which brings increased speed of development and unifies styles across multiple teams and apps.
5年前