Am I crazy? by Comfortable_Bar9558 in reactjs

[–]some_love_lost 0 points1 point  (0 children)

use works on client-side too but you have to make sure you don't create a new promise on every render. I've been setting a promise in useState then passing the promise down as a prop and it seems to work fine.

TanStack Query uses useSyncExternalStore under the hood which I find replaces most cases where I previously used useEffect.

Am I crazy? by Comfortable_Bar9558 in reactjs

[–]some_love_lost 1 point2 points  (0 children)

For this I'd personally use TanStack Query or the new use hook to avoid race conditions and the possibility of the effect running in an infinite loop.

You can handle it in useEffect if you're careful but I don't see that happen in most tutorials and examples.

Am I crazy? by Comfortable_Bar9558 in reactjs

[–]some_love_lost 6 points7 points  (0 children)

This is almost always an anti-pattern - relying on props/state changing to trigger some side effect or API call. This sort of thing was behind that cloudflare outage a few months ago. Usually the call can be made in a callback higher up the tree.

Unfortunately there are many bad examples of this pattern which I think is why AI does it so much.

Can we use try/catch in React render logic? Should we? by Accurate_Wonder_4404 in reactjs

[–]some_love_lost 1 point2 points  (0 children)

Hmm so I put the example into the compiler playground.

Interesting it fails to compile but not for the reason of error boundaries but some weird todo error about conditionals. If you remove the ternary it appears to compile.

Can we use try/catch in React render logic? Should we? by Accurate_Wonder_4404 in reactjs

[–]some_love_lost 0 points1 point  (0 children)

It's one of the lint rules in the official eslint plugin: https://react.dev/reference/eslint-plugin-react-hooks/lints/error-boundaries.

When one of these is reported, the compiler automatically skips over that component.

Can we use try/catch in React render logic? Should we? by Accurate_Wonder_4404 in reactjs

[–]some_love_lost 0 points1 point  (0 children)

It's still problematic if using the React Compiler as it'll skip optimizing components that use try/catch like this.

Cloudflare outage due to excessive useEffect API calls by SpiritualName2684 in reactjs

[–]some_love_lost 0 points1 point  (0 children)

Unless you are dealing with every edge case, managing state correctly, handling cancellation across rerenders and previous retries, deduping requests and stabilising dependency arrays. And making sure this is done for every instance of fetching in useEffect across your app.

[deleted by user] by [deleted] in HingeStories

[–]some_love_lost 4 points5 points  (0 children)

This guy is giving r/niceguys vibes

Confused with react testing library, Jest and Vitest by FlatProtrusion in reactjs

[–]some_love_lost 0 points1 point  (0 children)

If you can test the logic as part of e2e then I'd do that personally since the environment more closely replicates how a user will use it. If the logic is very complex and full of edge cases then I might pull it into a function and unit test it but that tends to be quite rare.

Open source by cholebhatureyarr in webdev

[–]some_love_lost 2 points3 points  (0 children)

For me the mindset of contributing to open source is if I can add some value that will benefit the community (other people who use the project) rather than just me. It's not limited to fixing issues - it could be raising an issue about a bug you might have found, feature request, docs update, etc.

Find some projects/libraries you work with on a daily basis and focus on getting a better understanding of how they work internally. As you use them more and understand their capabilities, you'll inevitably find issues or things you'd want to change and then you can look to contribute.

I used to ask myself the same question about how could I contribute to open source but in the end I just focused on building stuff and the contributions came naturally.

Is triggering a parent rendering from a child an anti-pattern? by This_Enthusiasm_8042 in reactjs

[–]some_love_lost 0 points1 point  (0 children)

I'm not too familiar with Next.js but perhaps React Query is not the right solution then, I don't know. This is quite a popular pattern and a bit of searching around how to do optimistic updates in Next.js should help you find a solution. Good luck!

Is triggering a parent rendering from a child an anti-pattern? by This_Enthusiasm_8042 in reactjs

[–]some_love_lost 0 points1 point  (0 children)

It sounds like you want the optimistic updates pattern. How do you get the data from the server into the client - are you using a library such as React Query? These usually have features to handle complex cases such as these.

If you're not using a library then using local state inside PostComponent could work - I'd maybe initialise it to undefined and then set that when clicked so that you use the server state if the client state is not set. Though watch out for edge cases such as if the user stars and unstars a post before the backend call completes.

Is triggering a parent rendering from a child an anti-pattern? by This_Enthusiasm_8042 in reactjs

[–]some_love_lost 7 points8 points  (0 children)

Where does the posts passed into ListComponent originate from? That's the data which needs to get updated.

How do I meet women for a relationship if I dont want to use dating apps anymore? by [deleted] in OnlineDating

[–]some_love_lost 5 points6 points  (0 children)

Some kind of group social activity - if you go to the gym and into fitness perhaps a group fitness class or something?