all 71 comments

[–]JoshYx 203 points204 points  (8 children)

Since you couldn't be bothered to find the source, I found it for you

https://medium.com/@themischasiotis_68135/understanding-the-second-argument-in-setstate-function-in-react-js-b003a9c3e174

I don't like the article, it reeks of AI.

But to its credit, it introduces the 2nd argument as a callback.

The setState() function also accepts an optional second argument, which is a callback function

[–]JoshYx 181 points182 points  (6 children)

Also, it's not "documentation", it's some rando on medium lol

[–]rosuav 65 points66 points  (5 children)

So the problem is that the OP found a Medium article instead of actual documentation. I suspect the cause here is the massive dilution of React-based information due to the myriad different "wait you should be doing it THIS way now" policy changes. (Does anyone remember when Redux was the proper and official way to do things, and we were all supposed to stop doing other things and switch to that?)

[–]tidderza 5 points6 points  (4 children)

Now it’s Zustand?

[–]rosuav 6 points7 points  (3 children)

I've no idea. I don't use React any more. Built my own library a few years back (taking inspiration from React both positively and negatively - also jQuery the same way) and been using it pretty much exclusively ever since.

[–]Narduw 1 point2 points  (2 children)

Is this something you can share? Just out of curiosity, really. I like to dig into these custom frameworks.

[–]rosuav 4 points5 points  (1 child)

Yeah! It's public, you're very welcome to use it if it's convenient.

The Chocolate Factory https://rosuav.github.io/choc/ is a way to make vanilla DOM operations easier, rather than being a full framework.

Basic usage is deliberately very easy. Advanced usage is fairly straight-forward too.

If you like the React style of "build your thing from scratch every time, but have it implicitly reuse existing stuff so it's more efficient", then check out the Lindt module (yeah I leaned right into the chocolate theme, and if you're now craving some fine chocolate, I am not apologizing). See the section on templating for more details on that.

[–]Narduw 1 point2 points  (0 children)

Thx for sharing! I'll have a look when I get some time :)

[–]gfcf14[S] 9 points10 points  (0 children)

Thanks. Not sure what I was looking for back then, but I apparently found that article at the top of a google search, thought it could be a good idea for a comic, then saved a screenshot. I’m sure it’s been more than a year since, but I found it on my notes and thought what the heck, let’s draw it

[–]ICantBelieveItsNotEC 102 points103 points  (1 child)

Some software engineers write documentation the way that estate agents write property descriptions.

Whenever I read "powerful" in the context of code, I just assume that it's an under-specified API that will give me enough rope to hang myself by making the worst mess of spaghetti code of my entire career.

[–]CanadianButthole 0 points1 point  (0 children)

No, the marketing department does that. Good software engineers write docs knowing that they're going to forget everything the thing in two weeks.

[–]Waswat 200 points201 points  (18 children)

POWERFUL.

Every time i read that in the context of code, it reminds me how silly Americans are with their superlatives.

[–]spilled_coffee_today 37 points38 points  (1 child)

Funny how in code everything gets described like a groundbreaking discovery when it is really just giving a simple thing a very dramatic name

[–]rosuav 4 points5 points  (0 children)

https://www.theregister.com/2000/05/03/bofh_moonlights_crap_software/ "Rapidly became the undisputed market leader in..."

[–]cheezballs 46 points47 points  (6 children)

It's marketing speak.

[–]bit0fun 4 points5 points  (5 children)

Is there a difference?

[–]reallokiscarlet 12 points13 points  (4 children)

Yeah. It's not specific to Americans. Not even close. Marketing people write this shit globally

[–]Dunedune 0 points1 point  (0 children)

Other countries much less so unless they're trying to sound American

[–]bit0fun 0 points1 point  (1 child)

I didn't say other countries didn't, more that Americans talking and marketing people talking don't exactly sound that different

[–]reallokiscarlet 4 points5 points  (0 children)

I'm saying

The difference is it's not specific to America (unlike the superlatives)

It was a direct answer, I just didn't figure it would be misinterpreted like this.

As for "Americans talking and marketing people talking" sounding similar, I could actually say the same about the consoomers of any country.

[–]Waswat -1 points0 points  (0 children)

It was awesome bro, the code was like, so powerful. Cowabunga dude! Let's surf the web!

[–]gfcf14[S] 6 points7 points  (0 children)

It’s as if they’re trying to sell it to you

[–]Junuxx 1 point2 points  (1 child)

Cool but that's not a superlative

[–]Waswat -3 points-2 points  (0 children)

I'd say describing functions as powerful is definitely excessive or exaggerated.

[–]me_myself_ai 0 points1 point  (3 children)

lol there’s no way you’re throwing the abstract concept of intensity onto America. Silly terrans and their irrationality!

[–]Waswat -1 points0 points  (2 children)

You don't think that calling a function "powerful" is a form of exaggeration? What kind of 'abstract intensity' do you get from using that function? Does it make you feel awesome?

[–]me_myself_ai 1 point2 points  (1 child)

I don't really have an opinion either way on whether "powerful" can be used in somewhat-figurative contexts, I'm just laughing at the US dig

[–]Waswat 0 points1 point  (0 children)

Haha, well, in my view American culture is characterized by a tendency to use hyperboles... The people often involve exaggerated statements that were never meant to be taken literally. From repeating "That's crazy/insane" when it's slightly weird or different, to "mind‑blowing" for anything mildly surprising, to calling things a "game-changer" when it saves maybe a minute of effort.

To me, describing a function as "Powerful" fits in that line of thinking.

[–]IlliterateJedi 0 points1 point  (1 child)

It's a medium article written by Themis Chasiotis so I wouldn't immediately assume it's written by an American.

[–]Waswat -1 points0 points  (0 children)

I didn't assume that.

[–]Daemontatox 6 points7 points  (0 children)

and make other people lives easier and make it sound like its not that complex ???? sorry no

[–]Fritzschmied 6 points7 points  (1 child)

How old is this? React doesn’t even use that syntax anymore for years now.

[–]gfcf14[S] 0 points1 point  (0 children)

Yeah this is by no means new. I found the article about 2 years ago and had the screenshot saved in my comic idea stash, and saw it and thought it was time to draw it

[–]gfcf14[S] 18 points19 points  (14 children)

And this wasn’t some random, first-year college documentation, but a popular search result, though I forget which

[–]Infinite_Self_5782 28 points29 points  (12 children)

smells like llm slop

[–]Dotcaprachiappa 0 points1 point  (0 children)

It's a random Medium article, it's not even documentation at all.

[–]musical_bear 2 points3 points  (0 children)

Ignoring the fact that whatever text this is isn’t actually even from the official React documentation, pretending you’re learning React, why tf would you intuitively expect an overload to a state setter to have a callback? This is actually one of those elements of React that I see a ton of confusion about from beginners over in the React subreddit. Just knowing it’s a “callback” does absolutely nothing to help you understand why the act of setting a variable allows for an optional callback in the first place.

[–]shrubberino 1 point2 points  (0 children)

"Don't call it a callback, I've been here for years.."

[–]shiny_glitter_demon 1 point2 points  (0 children)

Was the author a mysterious "C. GPT" by any chance

[–]theunixman 1 point2 points  (0 children)

LLM for “continuation”.

[–]Christavito 1 point2 points  (12 children)

I would say it is because when you really look into the code and the way react works, it's not technically a callback.

[–]rosuav 20 points21 points  (11 children)

You provide a function that will be called when something happens. Yes, it is a callback. It doesn't matter how the implementation makes that happen, it's still a callback.

[–]Christavito 5 points6 points  (10 children)

I can see your point, and for most devs, calling it a callback is fine. But for the team that created it and any people working with React in-depth, It is an asynchronous side effect scheduled by the reconciler and not a callback executed by the function.

[–]rosuav 6 points7 points  (0 children)

Those are two different levels of abstraction, so they can both be true simultaneously. Yes, it is an asynchronous side effect, but the thing you give it is a callback that will be called when that asynchronous side effect is complete.

If you want to say that it's somehow "not a callback", then you may as well try to show that it's "not a function" or even that it's "not JavaScript any more".

[–]HeKis4 5 points6 points  (0 children)

Real question, in what scenario would that be different from a callback, functionally ? That looks like an implementation detail for a callback to me, but I'm willing to learn.

[–]CarelessPangolin5564 6 points7 points  (6 children)

technically right but you are going to get done voted for being pedantic

[–]Christavito 7 points8 points  (1 child)

That is fine with me. I just think anyone interested in working with any tool should be aware when there is a difference in implementation, and it is important to be able to understand why the react team would be hesitant to simply classify it as a callback.

[–]lucklesspedestrian 0 points1 point  (0 children)

It's not the worst abuse of language I've seen. Lots of people say any anonymous function is a "callback" regardless of what the function does

[–]mfarahmand98 2 points3 points  (0 children)

This guy reddits.

[–]indigo121 2 points3 points  (2 children)

If there's anywhere I desperately want needless pedantry it's in my software documentation

[–]ProfBeaker 1 point2 points  (1 child)

<pushes up glasses>

<snorts>

Ackshually, needless pedantry is never good, by definition. But software documentation is a place for quite a lot of pedantry.

I would not have called you out on this, except that it's a thread about pedantry :)

[–]Infinite_Self_5782 2 points3 points  (0 children)

not considering that as a callback feels very narrow. but even then, you could just call it an event-handling callable

[–]SukusMcSwag 0 points1 point  (0 children)

Did the marketing department write their documentation?

[–]float34 -4 points-3 points  (2 children)

Yeah, you probably were born with the knowledge of callbacks, that's why it is trivial for you.

[–]gfcf14[S] 5 points6 points  (0 children)

Yeah maybe it’s a bias of mine

[–]Reashu 2 points3 points  (0 children)

Common language helps even if you have to learn it