Skip to main content
Published in News

Gnarly Learnings from July 2023

Gnarly Learnings from July 2023
Table of contents
  1. ComparisonValidator
  2. Active Storage Can Pre-Process Variants
  3. JavaScript's findLast() and findLastIndex()
  4. Partial Renders in Rails
  5. React.FC Removed From create-react-app Base TypeScript Template
  6. Contributors:

At The Gnar we are always reading, watching, and listening in order to keep our skills sharp and our perspectives fresh. Here are some of the resources we learned from this month.

ComparisonValidator#

Gone are the days when we need to write custom validators in Rails to determine if a start date begins before an end date! Back in 2021, the ComparisonValidator was added to Rails 7. While useful for solving the date comparison example above, that's not all it can do! It can also compare strings, and it allows for the flexibility of custom comparisons.

Active Storage Can Pre-Process Variants #

Earlier this month Rails added a feature allowing Active Storage variants to be pre-processed up front by adding preprocessed: true to the variant definition. This makes the attachment ready to serve from the outset, rather than requiring the variant to be prepared/transformed on the fly.

JavaScript's findLast() and findLastIndex() #

There are a few new Array functions included in ES2023, findLast() and findLastIndex(). The exciting piece is less about what these functions do (you can probably figure it out from the names) and more about the convenience that they provide. As a Rubyist by trade, I am used to a super developer-friendly experience when it comes to the readability, and accessibility of functions so it's great to see these being added to JavaScript, even if it took until 2023. 😉

Partial Renders in Rails#

Partial rendering allows you to create a consistent template with different sections, for example "title", "body", and "footer."  Then the templates can define content for each of those sections without having to know anything about the layout of the root template.

React.FC Removed From create-react-app Base TypeScript Template#

If you build React apps with TypeScript, you're certainly used to seeing and using the React.FC (or React.FunctionalComponent) type at the declaration of your functional components. The folks maintaining create-react-app have decided to remove this type from their template as they believe it is more harmful than helpful. I tend to agree, particularly around the implicit definition of children.

Contributors:#

Learn more about how The Gnar builds software.

Frequently asked questions

Do I need a custom validator to compare start and end dates?

ComparisonValidator, added to Rails 7, can check whether a start date comes before an end date. It also handles strings and custom comparisons.

Which new JavaScript Array functions are mentioned?

The post highlights findLast() and findLastIndex(), included in ES2023, for the convenience they provide.

Why was React.FC removed from the create-react-app template?

The maintainers believe the type is more harmful than helpful. The author agrees, particularly because of the implicit definition of children.

Stay In The Loop

Never miss an update. Get the latest blogs, webinars, and expert insights straight to your inbox from The Gnar.