Debounce behaviour is helpful when we want additional control over when a function is called. When implemented properly, we can call a debounced function any number of times, but it will only be invoked after a specified amount of time has passed from its last call. This is helpful in scenarios such as waiting for the user to finish typing before sending out a network request.
You may encounter difficulties when implementing this with React, as additional re-renders may disrupt timed callback behaviour.
Let’s see what we can do about this 😎
❌ What does not work: using debounce directly…
I’m a big fan of automating boring tasks. While it’s never been easier to create and share great software, handling the mental load of versioning and deployments can get tedious over time. Removing the subjectivity from this process can help to speed up developer velocity and decrease the potential for human error.
In this guide, we will:
As someone with a tremendously uncommon name, I often find myself…
Imagine this familiar scenario: a developer builds a life-changing todo application using React and has decided to leverage hooks to make the sharing of state logic much cleaner. Being a responsible developer with a passion for testing, they bring in jest and react-testing-library to start writing unit and integration tests for their components.
Upon implementing these component tests, a challenge arises:
How does one mock a hook’s value when its state exists outside the scope of a component?
To help solve this, we can leverage jest.mock()
Imagine that our component relies on a useAuth() hook to share state about the…
Getting these two to play nicely together was initially a frustrating endeavour. Here’s what eventually worked for me after some google-fu.
For this build I will be using webpack@2.4.1 and font-awesome@4.7.0.
Start by installing all your webpack-related NPM devDependencies.
npm install webpack file-loader css-loader sass-loader node-sass
--save-dev
Now we’ll bring font-awesome into our dependencies 😎
npm install font-awesome --save
After configuring your webpack.config.js to load Sass (tutorial here), we’ll add a loader to read the icons. We’ll also tell it where to look for the fonts.
webpack.config.jsmodule.exports = {
...
module: {
rules: [
// other loaders
...…
Software Developer from Canada 🇨🇦