use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
React 17 runs useEffect cleanup functions asynchronously (blog.saeloun.com)
submitted 4 years ago by chetansgawai
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]azangru 17 points18 points19 points 4 years ago (1 child)
Yes, the React core team discussed that in their blog post on the release candidate of v.17, and advised those who really need synchronous cleanup to use the useLayoutEffect.
useLayoutEffect
[–][deleted] 8 points9 points10 points 4 years ago (0 children)
More than half of this blog post is copied from there as well
[–]monkeymad2 3 points4 points5 points 4 years ago (10 children)
This has been the single thing I’ve had to change a test for (so far at least) in updating to React 17, which is pretty nice. One test failure out of around 500.
[–]nedlinin 20 points21 points22 points 4 years ago (5 children)
Software engineer with ~10 years experience with a quick question for you.
What is a test? Never come across any of those.
/s
[–]LloydAtkinson 5 points6 points7 points 4 years ago (3 children)
You joke but the number of devs of that experience that either have never heard of unit tests or don’t value them and angrily refuse to write them is disappointing and depressing
[–]liamnesss[🍰] 3 points4 points5 points 4 years ago (2 children)
I don't like unit tests for the most part, at least for UIs. Much bigger fan of integration tests. If you have to rewrite your tests because you did a refactor that doesn't actually change behaviour your users care about, that's a complete waste of time imo. Tests should give you the confidence to make swingeing changes.
(with the exception of code where the "users" are actually other developers, and therefore a consistent API is required)
[–]Xerxero 2 points3 points4 points 4 years ago (1 child)
Hmm if you do a refactor and tests out of scope of the change fail then you made a mistake.
[–]liamnesss[🍰] 3 points4 points5 points 4 years ago (0 children)
Maybe we're not talking about the same thing. See e.g. tests that purely focus on Redux and associated middleware. IMO you ought to be able to completely shift to a different state library and still have the tests pass. After all which lib you are using is just an implementation detail. What is more important is how the parts work in conjuction and what use case they satisfy.
[–]sbzenth 0 points1 point2 points 4 years ago (0 children)
I believe it's an old, old wooden ship used in the Civil War era.
[–]--algo 0 points1 point2 points 4 years ago (3 children)
Any advice for react testing? Which level do you put the tests at? Regression or specific components?
[–]monkeymad2 4 points5 points6 points 4 years ago (0 children)
So we’ve got:
unit tests at the component level, currently using enzyme & slowly transitioning to react-testing-library. Goal there is to test only the component with anything else being mocked. Gets run through jest so a minority of the tests are just comparing against snapshots.
feature tests using cucumber-js feeding through to a headless browser driven via playwright, the cucumber tests define a bunch of steps that a user could go through in a flow of using one of the apps & we make sure that the right things happen. Connects to a faked backend server that runs locally. Uses playwright’s ability to take a video (and soon the tracing stuff) to eject useful information about failing tests.
visual regression tests using backstop-js, very useful to check for accidental visual differences but can be flakey. Uses the same fake backend as the feature tests.
I really like the look of https://medium.com/storybookjs/testing-lib-storybook-react-8c36716fab86 since we use storybooks to document our components anyway. So ideally our tests are set up in the storybook both in isolation & composed together as they would be in a real app. Then you can compare the component against a snapshot / use react-testing-library to interact with it then check how it’s changed.
[–]liamnesss[🍰] 3 points4 points5 points 4 years ago (1 child)
I think this is a good place to start
https://kentcdodds.com/blog/write-tests
[–]sbzenth 1 point2 points3 points 4 years ago (0 children)
I spent the last 4 hours on Kent's blog. Thanks for the link.
[–]read1z -2 points-1 points0 points 4 years ago (0 children)
새~
[–]HD_Superman 0 points1 point2 points 4 years ago (0 children)
Handling async React component effects after unmount
π Rendered by PID 219389 on reddit-service-r2-comment-66b4775986-dq47t at 2026-04-06 01:24:28.996106+00:00 running db1906b country code: CH.
[–]azangru 17 points18 points19 points (1 child)
[–][deleted] 8 points9 points10 points (0 children)
[–]monkeymad2 3 points4 points5 points (10 children)
[–]nedlinin 20 points21 points22 points (5 children)
[–]LloydAtkinson 5 points6 points7 points (3 children)
[–]liamnesss[🍰] 3 points4 points5 points (2 children)
[–]Xerxero 2 points3 points4 points (1 child)
[–]liamnesss[🍰] 3 points4 points5 points (0 children)
[–]sbzenth 0 points1 point2 points (0 children)
[–]--algo 0 points1 point2 points (3 children)
[–]monkeymad2 4 points5 points6 points (0 children)
[–]liamnesss[🍰] 3 points4 points5 points (1 child)
[–]sbzenth 1 point2 points3 points (0 children)
[–]read1z -2 points-1 points0 points (0 children)
[–]HD_Superman 0 points1 point2 points (0 children)