You can invalidate an active query to get it to force refetch with React Query. Here's how you can force refetch after a mutation, or on a button click, to check for updated data.
Here's something that caught me out this week - skip and limit order in MongoDB. The order of skip and limit isn't important in chaining (like `find` commands) but it is important in aggregation.
In React Query, the cacheTime and staleTime options impact how long data gets stored on the client and how often it's re-fetched from the server. Let's look at the difference between cacheTime and staleTime - and how changes to one can impact the other.
If browsers save old code bundles for your React app, it can create errors and problems loading your app for your users. Here are some cache-busting tips for React in production.
This is how I store paginated queries when I also want users to know the total results count and total number of pages for paginated data.
Drag and drop can be a little tricky to implement. Here are some common problems you might run into and how to fix them to get your drag-and-drop working like a charm.
One of my favourite features of Trello is how you can drag and drop your cards around, so here's how I created a Trello-like drag-and-drop kanban board from scratch in React.
Drag and drop is a pretty cool feature to add to your web applications. But it can be a little tricky. With some trial and error, here's how I built a reusable drag-and-drop component for React (and all the code!).
As I use a cloud IDE, sometimes the only copy of my code is in a GitHub repo. And that got me worried. Here's how I create a backup on Bitbucket.
I’m really interested to know how people take on a big full-stack project. Do you start with the front end (client) or the back end (server)? So I’ll share my approach - which is one small feature at a time - and why it works for me.
Both throttling and debouncing are useful ways to slow down how often a function runs when it's called multiple times. Throttling allows a function to be called once during a timeframe, and debouncing calls a function once after the timeframe.
In this blog post, we will create a `toPlural` function that does slightly more than just add an "s" to the end of a word if the number is more than one!
Here's how to scroll to an element after you render a component in React with `useRef` and `useEffect`. And if you need to do it more than once, I've included a custom `useScrollOnRender` hook you can use.
There's more than one way to update a document in MongoDB. Here's when (and why) I use `findOneAndUpdate` instead of `updateOne` to update a document with MongoDB in Node.js.
When you use the `upsert` option with `findOneAndUpdate` in MongoDB, it's not easy to know if the document was inserted or updated. Here's how I check if a document was created when returning the document before, or after the update.
If you want to automatically have your files expire (and get deleted) from DigitalOcean Spaces after a certain number of days, you can do it with s3 lifecycle rules. You can’t set this up in the web interface, so here's the code you need to create the rule using Node.js.
When you send a query string `req.query` back to Express, true and false booleans are converted into strings. Here's why, and how I parse them back to booleans - but only sometimes!
Here are three ways you can pass a function as a prop in React, with and without parameters - all while avoiding infinite loops!
In this blog post, I'll show you how to fix React rendering `0` in your `&&` conditions by using `!!` to convert it to a Boolean. But I'll also explain why it works so you can avoid this problem in the future!