|
You can also use libraries like nock to mock the actual web request behind the scenes
|
# ¿ May 26, 2021 19:41 |
|
|
# ¿ May 6, 2024 04:50 |
|
The other question to ask yourself is "Do I want my co-workers to be the kind of people that agreed to go through this same bullshit?"
|
# ¿ Oct 8, 2021 02:16 |
|
Nah that is normal. Union types are better in every way.
|
# ¿ Oct 16, 2021 00:27 |
|
If that's a thing you need to do there is a slightly hacky workaround https://twitter.com/housecor/status/1387083288989380610
|
# ¿ Oct 16, 2021 06:04 |
|
fsif posted:And now in React 18 strict mode, they've been forcing useEffect to run twice, which effectively breaks a lot of common implementations of the hook (like data fetching). I was going to say "This should be totally fine as long as you're properly handling the cleanup on the effect" but the fact that almost nobody actually does that seems to be the problem they're trying to address at the framework level.
|
# ¿ Jul 8, 2022 22:17 |
|
nx may be an option too
|
# ¿ Jul 13, 2022 19:52 |
|
prom candy posted:After doing some more research I still don't really understand how you're supposed to do safely data fetching in useEffect now. I guess for any heavy computation like that you need to create a ref that says "this already ran so don't run it again?" Also yeah I know I should just use a third party data fetching lib and I normally do. useMemo is what you should be using to avoid redoing heavy computation rather than useEffect+ref For safe data fetching the main thing is to just 1) run any cleanup necessary in the useEffect cleanup function and 2) be aware that responses can still come back after the cleanup func depending on how you aborted the initial request (and can arrive out of order coming back even after the newest rendered useEffect fetches successfully). https://beta.reactjs.org/learn/synchronizing-with-effects#fetching-data
|
# ¿ Jul 19, 2022 23:54 |
|
worms butthole guy posted:So I have a useeffect that fetches a API every 5 seconds and updates data. One thing I'm not particularly good at is remmebering how to only save different data to state. So right now I have By comparing the state vs data before calling setState? That's only if you don't want the state to update at all. The main alternative is to just update the state every time and make sure whatever components depend on it to render are properly memoed so they won't rerender if the relevant portions of the state haven't changed.
|
# ¿ Jul 20, 2022 23:35 |
|
Can you SSR the page with the API items in it?
|
# ¿ Aug 31, 2022 20:12 |
|
The Merkinman posted:Just so I'm understanding... When back is pressed to instead call a server side rendered version of the page? Yeah, and if you need direct links to particular items or places in the page you can render them with anchors or just use your scroll position now that the page is static. Whether that's reasonable kind of depends on the size of the response from the API and whether you can work an SSR page into your existing SPA architecture.
|
# ¿ Sep 1, 2022 05:12 |
|
Lumpy posted:Is anyone publishing two or more discreet packages from a single monorepo? If so what are you using, and do you regret doing things this way? Yes, nx, and no
|
# ¿ May 12, 2023 21:55 |
|
teen phone cutie posted:but also, pinning all your versions in package.json is a thing you should more-or-less enforce always Because you don't trust them to follow semver or you don't want to rely on your package managers resolution logic?
|
# ¿ Nov 3, 2023 21:37 |
|
|
# ¿ May 6, 2024 04:50 |
|
IMO React itself is great mostly because it doesn't try to do everything for you however that also means the community solutions for the missing pieces are typically much lower quality in terms of dev experience. Agreed that most of the ecosystem is a mess.
|
# ¿ Apr 11, 2024 03:07 |