2,790 karma · joined February 14, 2016
I haven't heard any other reports, and it's working on my fully-updated iPhone hoping this was just a hiccup.
As I’ve gotten more experienced, my code has gotten less fancy and more verbose. A single terse expression is broken out into 3 or 4 statements, defining variables that capture and name fragments.
But yeah, otherwise really enjoyed the article!
Granted, many react apps aren’t serverside-rendered, so these numbers are still useful and interesting. But I would say that if performance is a priority, moving to an SSR solution (or away from React altogether) would have a way bigger impact on performance.
Folks in the comments seem to be making pretty broad statements about what is good or bad, and I just want to let readers know to take everything with a huge grain of salt.
In my case, fear of making things worse was the biggest obstacle — pushing myself to trust that typing isn’t dangerous, even though it hurt, was critical in my recovery. This is awful advice for many people with RSI, though.
My advice: see a physical therapist first. They can often help, or point you in the right direction. If months pass and nothing seems to help, seek out alternative explanations and keep an open mind. Check out The Mindbody Prescription” by Dr Sarno. It was the missing puzzle piece for me.
I created this project because I was sick of how hard it was to google for JavaScript operators; Google ignores certain characters like "?". I would remember the syntax, but not what it was called, or exactly how it worked… and it was surprisingly difficult to research!
This little tool allows users to write the syntax for a given operator, and it provides a name, a description, some examples, and a link to the MDN documentation.
I expect it to be a useful bookmark, for the next time you can't remember what the heck the "?." (Nullish Coalescing) or "??=" (Logical Nullish Assignment) operators are called :)
I touch on this in the article, but I should say: I'm an edge-case when it comes to CTS. Most cases resolve spontaneously. Part of it is that my nerve dislocates when I bend my elbow, and this mobility causes a bunch of additional friction / inflammation. This happens naturally to about 13% of the population, and mine is particularly pronounced.
All this to say, if you ever do start to get a burning or tingling in your elbows or wrists, or get numbness in the hands, it'll likely go away on its own, or with conservative treatment (a physical therapist is a great first step!).
And, for those who also fall into my unlucky percentile, hopefully it helps to know that there are tools and a community that exist to let you keep working without needing to use your hands at all!
I also don't like the idea of "reaching in" and setting widths on all children. Feels like this could cause problems, especially on replaced elements like images/videos. Not to mention that it just feels wrong when combined with a component architecture, where I might expect a <Heading> component to control its own destiny. In fairness, my solution also reaches in to apply a grid-column, but grid-column is a property that only makes sense when combined with a parent's `display: grid`. So it bothers me less.
Enough people have brought this up that I wonder if I should have addressed it in the article... but then I realize, it's not my job to argue against or "disprove" all alternative ideas. I'm not claiming that my way is the best way, I'm just sharing a cool trick I found :)
What I meant is that there is no way to tell certain children to disregard the constraints of a container; if a parent is 800px wide, there isn't a way to say "keep this child in-flow, but fill the viewport".
The alternative you propose is problematic for a couple reasons:
- I don't like "reaching in" to child elements. Especially in a component-focused architecture, it's a quick way to make a mess. My solution DOES reach in to apply a grid column, but that property only makes sense within the context of a grid, so it doesn't seem as problematic to me.
- the `ch` unit doesn't work properly when applied individually to different elements; an `h1` with 65ch width is going to be much wider than a `p` with 65ch width. You need the width to be applied to the parent, so that it remains consistent
- It's likely that you already have a constrained container, if you're adapting this solution to a page that already exists. If so, your approach isn't really workable without a major overhaul.
I'd also just add, the nice thing about using Grid is that it's super extensible. If you want to add a sidebar, it's quick and straightforward.
The only React-specific thing is the useEffect call, which is essentially comparable to window.onLoad.
My point is that my example is complex because some client-side code is necessary. The snippet you shared is nice pseudo-code but a real implementation would be comparable in complexity. Either way you need to learn some stuff, and then it’s a few lines of code.
That said, I challenge the assumption that this way is _that_ much more complicated. I’ve built similar things with PHP, a long long time ago, and it was a lot of the same pieces. The only part that feels truly more complex is the re-render necessary in React, since the data comes in async, but this is hugely beneficial since it means the page doesn’t need to be server-rendered / the user isn’t staring at a white page waiting for the RPC to the database.
Edit: realizing that there are ways to do this in PHP that aren’t blocking, like if you use an image tag that resolves to the right image, but honestly that way seems wayyy more complex to me, especially when factoring in accessibility / screen-reader-friendliness.
Sharing a book I released today about building developer portfolio sites.
A few months ago I reviewed several hundred dev portfolios on twitter, and found I was giving the same feedback over and over. I also had a lot to say on the subject; I've been involved with hiring for many of the orgs I've worked for, and I've reviewed a whole lot of portfolios in that capacity. I also work as a career coach for a local bootcamp, helping recent grads land their first role.
The book distills everything I've learned into a tactical guide. A portfolio site is only one small part of the job hunt, but I believe doing it well can offer a huge advantage.
I've made it free-to-download because it's targeted at folks looking to break into the industry, people who just invested their life savings into a bootcamp or graduated college with debt. I feel weird charging for this.
(Sorry for the double-post: forgot the "Show HN" prefix, and couldn't delete the original!)
Sharing a book I released today about building developer portfolio sites.
A few months ago I reviewed several hundred dev portfolios on twitter, and found I was giving the same feedback over and over. I also had a lot to say on the subject; I've been involved with hiring for many of the orgs I've worked for, and I've reviewed a whole lot of portfolios in that capacity. I also work as a career coach for a local bootcamp, helping recent grads land their first role.
The book distills everything I've learned into a tactical guide. A portfolio site is only one small part of the job hunt, but I believe doing it well can offer a huge advantage.
I hope it's helpful!
I don't have the energy to debunk some of these replies, but let me quickly say:
1. The reason that this is a hard problem has nothing to do with React, or Gatsby. It has to do with the strategy of precompiling HTML and not having a runtime server, an approach with many many benefits (described here: https://joshwcomeau.com/gatsby/a-static-future/). If you're wondering why anyone would put up with all this tomfoolery for a dark mode, please read that so you can understand the benefits to this approach.
2. "React is overkill for static sites" is a debate I am not trying to have, but I can say that for my blog (the site that this post is about), React has allowed me to do lots of cool things that would have been much harder otherwise. And using Gatsby means that I have first-meaningful-paint performance that beats a PHP template with no JS, since my site doesn't have to do any database lookups or real-time HTML generation. I am not saying that this is the right approach for every website, but it was 100% the right choice for this one.
4. Many of these replies are making suggestions that are discussed in the article itself. CSS variables are not an alternative to this solution, they _are_ the solution (my solution wouldn't work without them!). Please read the post before forming an opinion about it.
I hope that helps clarify some things! Hope you're all doing alright and staying home.
- As someone else said, it manages playback state. This is technically managed by a third-party library, but we expose an `isPlaying` boolean which is held in React state
- It lazy-loads Howler, the underlying audio dependency. This means the bundle cost is ~1kb instead of 11kb (gzip)
- It memoizes all the callback functions to avoid breaking React.memo / PureComponent components
const [playBell, bellOptions] = useSound();
const [playBoom, boomOptions] = useSound();
It follows the convention of other React hooks, like useState.
Specifically, they had real problems with their current system, which they documented here: https://phabricator.wikimedia.org/T225453. Then they explored the available options in the ecosystem and came up with the one they thought would best fit their needs.
If you're gonna be critical, at least take the time to understand what they're doing and why.
Even in this case, a loading solution works just fine, but it's the exact same pattern. You'd just `return <Spinner />` instead of `return null`. You also face the same issue, if you don't wait until post-mount.
In the case of something like a blog, though, you anticipate folks sharing the URL. It'd be kinda strange to inadvertently share persisted settings (or worse, stuff that's maybe a little personal)
Thanks for the heads-up.