1,689 karma · joined Mar 3, 2021 (5y ago) · 450 submissions
comment 3y ago · link · parent
Ah yeah, that does take a while to unpack. I think a lot of the complexity there is dealing with a non-react library and the dynamic import(s). Binding non-react libraries can be a bit rough.
I do think it's a good example to show the big advantage of hooks, if you look at the use of the hook, super clean: https://github.com/graphql/graphiql/blob/50674292c55eadf0e61...
Great way to contain complexity and make usage really clean and simple!
comment 3y ago · link · parent
This might be controversial but imo the lack of state management in React is a pro not a con. It means the community can innovate instead of being stuck with whatever the framework provides as is standard with most other frameworks. A lean focussed but flexible API.
You can choose the flavor that works for your, patterns like React Query, SWR, Zustand, the Atom based stuff, it's all a big #win imo. I like having options.
Also I'd say changes in preferences are not exclusive to React. React did make the hook change (while still supporting the old!), but otherwise the preferred approaches are not per se exclusive to React.
I would add that there is nothing wrong with sticking to what you are using atm. You don't have to use the shiny new thing if the old works well!
comment 3y ago · link · parent
1. It’s hard to reuse stateful logic between components
2. Complex components become hard to understand
3. Classes confuse both people and machines
See https://legacy.reactjs.org/docs/hooks-intro.html#motivation for details. Agree or not, but it is a very intentional and well motivated direction.
comment 3y ago · link · parent
The situation is calling setState from useEffect, which triggers a render, triggers the setState, render, etc...
If you setState in componentDidUpdate without any guards you will end up with the same loop. I don't remember how debugging this worked, but I'm pretty sure it wasn't pretty.
As to big messy components: I don't think you can blame that on hooks. Hooks make it easier to split all of that up so you have isolated well contained chunks of logic that are much easier to test, debug, and manage.
Vue; not super familiar but I believe they use reactivity right? I think reactivity can be nice, but is also not as great as it's made out to be as it gets tricky as soon as you need to take control and prevent extra renders etc. A lot of it is making diffing and memoization less explicit, which can be nice, but also has some tradeoffs.
comment 3y ago · link · parent
I also find functions much easier to read as there is no "this" and you can simply read them top to bottom for order of execution.
comment 3y ago · link · parent
But in terms of sales the branding is probably even more important, brands are hugely important in selling products, and fonts/typography are a big part of that. I did not focus on that as the article made the aesthetics-do-not-serve-purpose claim, but for sales branding is as relevant if not more relevant.
So if you are selling things I think you can pretty easily justify nice fonts to make your brand and products more desirable.
It does matter what your brand is of course, if your USP is cheap no frills a system font might serve that well.
comment 3y ago · link · parent
Classes have lots of rules and best practices to prevent a mess, just like hooks. Also stateful classes are notoriously hard to debug as everything can change everything all the time.
I think you also should try hooks for a bit. Some of your statements about them are incorrect or really not that prevalent in normal use, you might be surprised how nice they can be. Especially use react-query or swr for fetching and something like zustand for state.
comment 3y ago · link · parent
They are imo not ideal as they are hard to memoize because of the render function. It’s funny that if you try to memoize renderprop components you likely have to use some sort of inputs array just like hooks.
Besides the memoization issue it also gets pretty messy if you need to implement many of them. Instead of just putting things in variables you are now nesting many levels deep.
I think renderprops and hooks are functionally not that different, but hooks have better ergonomics when using many.
comment 3y ago · link · parent
I think this might be quite common, if you haven’t experienced HOC hell I can understand the confusion why hooks are necessary.
In terms of putting it in a function: there is only one state object per component, you could pass setState around, but you can imagine what would happen if many functions call it. It’s also a lot more effort on the implementation as you would have to basically pass state, and call do some sort of update in the lifecycle methods. It would probably work for one function, but with many it will get problematic. You would almost have to write your own pseudo hooks framework to make this work in a decent way.
comment 3y ago · link · parent
You can "sort of" reuse component logic with classes, the most common way is by using Higher order components (see https://legacy.reactjs.org/docs/higher-order- components.html).
The example in that article is pretty good: Subscribing to some external data source. That requires on mount, state, and on unmount.
Using HOC's is not actually reusing logic though, it's creating more components and wrapping them to compose the logic. It's a workaround.
HOC's have a bunch of downsides, imo the most obvious one is the props; you need to pass the previous props, and merge in the new ones. That can create conflicts. Another typical one is refs. You need to be very meticulous about structure and how you compose and order your HOC's to make sure it all works.
In hooks you can define this stateful logic truly disconnected from a component, resolving a lot of the issues of HOC's as you can just call a bunch of functions without impacting the render tree. The "plumbing" is much simpler.
Hope that is sort of clear, but let me know if I should clarify any of this.
comment 3y ago · link · parent
Hooks are better because they allow you to reuse component logic, impossible with class components. They solve all the issues and gotcha's of HOC's.
Don't compare class components with hooks, compare HOC's with hooks.
The best way to grow appreciation for hooks is to try wrapping many HOC's and deal with conflicting props and "innerRefs". People seem to very easily forget the horrors of the old.
Also lets be real, hooks aren't that bad. Yes dependencies arrays and useEffect take some getting used to, but I rarely get into situations where I actually get into questionable territory. Use react-query/swr for fetching, use Zustand (or whatever) for state, and you cut out 95% of the problems.
Anyway, the new docs are great, well done, nice work!
comment 3y ago · link · parent
MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/...
Demo: https://font-display.glitch.me/
More info, pro/cons: https://www.smashingmagazine.com/2021/05/reduce-font-loading...
And there is even more on the way: https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/...
As to the "better or not", read my previous comment(s).
comment 3y ago · link · parent
There is a scale to it of course. It's not like aesthetics can fix unusable products, it's just one of the tools you can and should use. And this is just usability, ignoring the value of branding, identity, etc.
If "custom fonts are good or bad" is imo not something you can get a definitive answer on. The impact on perception of usability obviously depends heavily on the fonts that are loaded, how they are used, and the rest of the page. Making broad statements will probably miss the nuance of usability and user experience.
Loading time is also a bit of a strange thing to take as a downside. Loading fonts does not have to be blocking (see font-display css), also there is a difference between loading 2 font files or 17, fonts are usually cached, and we even have variable fonts these days reducing size significantly. In other words it depends on the situation.
As with most usability topics the real way to find out is to test your use case. In my experience a few kb's more or less is not going to have a significant impact in many situations, especially if they are loaded in a non blocking way.
By all means test your case, it's always a good idea to test, and you will likely find 10 issues more urgent and more important than a couple of fonts.
comment 3y ago · link · parent
Fonts and typography are hugely important, especially in minimalistic styles.
I think there is also a misunderstanding in this article that aesthetics don't serve purpose. Aesthetics have impact on how things are perceived, meaning it actually has impact on the user experience https://www.nngroup.com/articles/aesthetic-usability-effect/
comment 3y ago · link · parent
That's often conflated, and actually the point I have been trying to make; you can say a lot of wild stuff legally, but you can not expect others to just accept it, not react to it, and not change their opinion of you.
There are also things that should be illegal, as example do you think death treats are fine? Or is that what you are referring to in my comment?
comment 3y ago · link · parent
Things you can not influence, things you can not change, things that do not harm others.
The intolerance towards intolerant is necessary for that to happen, which explains the battle.
People censoring themselves to not be hateful might honestly be a good thing, maybe they should figure out where those thoughts come from and if they should reconsider them. I would advocate for them to get help, therapy, social support, whatever they struggle with. I think being caring and empathetic strengthens society in the short and long term.
comment 3y ago · link · parent
If it is in fact all lies etc, then sure. But, I do think this is often exaggerated, and a lot of times "start a conversation about incredibly nuanced topics" might not be so nuanced and in fact hateful, look at dog whistles for example. That there is no tolerance for intolerance is kinda necessary (paradox of tolerance). Idk the case you are referring to so can't say if that's relevant to this situation or not.
I do strongly disagree that people suck. My experience with people is that generally they mean well, try to live their best live, and wish well on others, even if they might disagree on some things. A good test is to just think about the people you interact with day to day in real life, not tv, not twitter, not whatever. That's reality.
comment 3y ago · link · parent
That distinction is relevant to the question as the reaction to a controversial take, something that's likely to cause disagreement, is very different from the reaction to hateful speech. If it's not the case here; great!
If you read the rest of my comment I mostly say it's totally fine to have controversial opinions. At the end, albeit in jest, I even refer to my own controversies. It is true though, I often disagree with people on many topics, but I have not been censored.
My main point through all of it is that free speech is not free from consequences, everything one does has consequences, positive or negative. Expecting everyone to just embrace and except everything is just not realistic also not fair. Say what you need to say, but also expect people to react.
comment 3y ago · link · parent
If you stay within the law you are totally fine to say whatever you want, but it's a fuck around and find out situation, there might be consequences. If you say wild shit at work your employer might rethink your position, if you say wild shit to your friends they might not appreciate your company anymore, if you say wild shit online the platform might remove it. This is imo fair, you get to make your decisions, others can make theirs.
"Questioning a narrative" sounds innocent, but can certainly be used in hateful and malicious ways. The same rules apply; you can likely say it, but people might not appreciate it, and that's ok.
Often "I want to say controversial things" is a way to say "I want to say hateful things". The tolerance for hate speech is decreasing and hopefully will decrease further, which is great. If that applies to your situation (and I'm not saying it does), I suggest you question your narrative a bit more.
If it's not about hate speech you can absolutely discuss controversial takes, given that the other people are willing to hear about them and you have some decent arguments to back them up. I have plenty of controversial coding and design takes, nobody ever even tried to censor me, and some even agree!
comment 3y ago · link · parent
I think it almost always comes down to one thing: Can people achieve the thing they want to achieve in a somewhat efficient way?
If the answer is yes there is lots of tolerance for all sorts of crap before people experience it in a negative way.
That means managing the experience. As example a multi minute upload process can be totally fine if handled properly, a .5s delay on an input can make it unusable. My point being; reality is a lot more nuanced than the blanket "it all sucks, and performance is everything" statement, and personally I don't think it's helpful. Unless we can actually look at metrics and assess their importance and how we can address them.
Don't get me wrong; we should absolutely keep trying to improve, especially crafting well made usable interfaces that are a delight to use. Performance is certainly very important, but it's not the be all end all of user experience and atm wrongly used to justify silly points why [my fav framework] is so much better than React.
comment 3y ago · link · parent
Nngroup used to publish analyses of the state of usability, but I don’t think they have done one recently.
The old ones always showed progress, and that’s also what I would expect talking about the average situation.
Average progress doesn’t mean there are no shitty situations and we should always strive to improve, I just think claims like this are not helpful as they are used to make blanket statements about nuanced situations.
Unless you can back them up of course, and I would still love to see the data if anyone can find it.
comment 3y ago · link · parent
Most things are fine when done in moderation, most things are bad when taken to the extremes.
"13 days to go" suggest this was some crazy regimen, if you would do that to prisoners I bet it's actually considered torture.
If I read about his past, it sounds to me like he might have some underlying mental health problems that would be good to address. Not by guru's, retreats, or pseudoscience, but psychologists and other professionals.
I think he does come to the right conclusion that the extremes can be very harmful. They are not that far from cults, always some guru or leader, then many people blindly following their weird practices based on absolutely nothing but pseudo science and believe, with a tendency to get more extreme (and more expensive!) the deeper you get into them.
Meditation is fine if done in moderation and as long as you don't expect it to solve all your problems. It can help with certain things, it also won't solve serious mental problems.
Working through mental health problems is no fun and a lot of work with many ups and downs, there is no easy solution, there are no shortcuts. Get professional help, get therapy, get medication if needed, be kind to yourself, and just keep working at it one step at a time.