Gnarly Learnings From June 2022
Tags: react, rails, css, testing
Published: 2022-06-22 11:32:26

We love reading, watching, and listening to constantly update our skills and learn new perspectives. Here are some of the exciting pieces we learned from this month.

## [Goodbye, useEffect](https://www.youtube.com/watch?v=HPoC-k7Rxwo)

In this talk, David Khorshid discusses the awkward undesirable aspects of using `useEffect` to handle side effects. Specifically, `useEffect`'s proclivity for entering infinite loops and React 18 running `useEffect` twice on mount by default 🤮. He suggests several alternatives to use in react projects which he feels are less treacherous, including options like using state machines/external data stores to handle side effects or using `React.Suspense` as an alternative to fetch data early.

## [2022 Ruby on Rails Community Survey Results](https://rails-hosting.com/2022/)

This report is the combined efforts of 2,660 members of the Rails community across the globe. The comprehensive data set touches on everything from demographics, to work environment, user base, versioning, Javascript pairings, most-loved gems, and SO much more. There are also some great "community insights" sprinkled throughout the report in addition to all of the quantifiable data. If you're a rubyist or considering ruby for a project, this article does a great job of portraying the state of modern ruby/rails development.

## [Tips for Using FactoryBot Without an ORM](https://thoughtbot.com/blog/tips-for-using-factory-bot-without-an-orm)

As we continue to level-up our skillsets as developers in Rails, the utility of POROs (Plain Old Ruby Objects) becomes more apparent and appealing. Sometimes, the business object(s) you create do not require persistent storage to a database and are, therefore, outside of the scope of an [ORM (Object Relational Mapper)](https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapping) like [ActiveRecord](https://guides.rubyonrails.org/active_record_basics.html). But how do we maintain simplicity in our test suite and continue to leverage helpful testing libraries like [FactoryBot](https://github.com/thoughtbot/factory_bot) without one? This instructional article explores how to implement factories for POROs including common pitfalls, building nested resources, and factory linting.

## [The State of CSS 2022](https://web.dev/state-of-css-2022/)

It's a well-known fact that our industry is ever-changing - even older technologies like CSS are (thankfully) constantly evolving and being improved upon to support this exciting new era in web development. Rarely, however, do we get access to a compiled list of updates that occurred over the course of the year _and_ upcoming work for our favorite tech. Enter "The State of CSS 2022". This was presented as part of Google IO 2022 and serves as a jumping-off point to understand today's CSS features and get excited about tomorrow's!

## [Presenters Compared to Decorators, Strategies, and Composites](https://thoughtbot.com/blog/decorators-compared-to-strategies-composites-and)

There are several ways a Ruby class can be extended. The way in which we extend it will tell us how we want to identify our extension. Are we adding functionality? Are we adding presentational elements? Are we adding both? Here's an old-but-still-relevant post from Thoughtbot on a few of the choices.

## [Testing Techniques: The I/O Table](https://thoughtbot.com/blog/testing-techniques-the-i-o-table)

Testing complex SQL queries in our Rails applications can be _almost_ as challenging as writing them. The correctness of a test is one thing, but ensuring that the test is readable and maintainable is a completely different animal, because tests in this context often require extensive setup and result lengthy and confusing outputs. This article demonstrates testing an SQL query via an input and output (I/O) strategy. The author's approach allows us to use raw data to forgo complicated setup processes and to make the test(s) more clear. The output even looks like tabular data - neat!

## [How to Access Hash Values Like Methods in Ruby](https://dev.to/software_writer/how-to-access-hash-values-like-methods-in-ruby-4b1k)

Learning about new ways to manipulate data in Ruby is always fun. This article details a way to access hash values as if they were methods via the [ActiveSupport::OrderedOptions](https://api.rubyonrails.org/classes/ActiveSupport/OrderedOptions.html) class. Initially, it wasn't clear _why_ someone would reach for this over the default syntax, but the author pointed out that syntax can be helpful in keeping configuration files clean and readable. Apparently, this can be observed in the wild in the [Propshaft](https://github.com/rails/propshaft) (an asset pipeline library) codebase, which uses it to define `config.assets` in `Railtie`.


## [Shale](https://www.shalerb.org/)

Serialize Ruby data structures into JSON, XML, and YAML, and back again.

_Learn more about how The Gnar [builds software](https://www.thegnar.com/software-development)._