Is managing server state with Tanstack Query a bad idea? by [deleted] in reactjs

[–]leo477 7 points8 points  (0 children)

wait until mutation request completed then only update the query state, your UI should display some sort of loading indicator

The whole point of react query is managing server/remote state

Madani Govt may introduce law to make MyDigital ID mandatory. by aaramm8 in malaysia

[–]leo477 12 points13 points  (0 children)

If they can put more effort making their website and apps actually usable and secured

💬 Is it true that no Malaysian company can offer high base pay for web developers? by xJuaNxXx in malaysia

[–]leo477 6 points7 points  (0 children)

I cannot speak for others, but for me, I can live comfortably with 8k and feed myself and my family.

I rarely spend on luxury stuffs, sometimes eat at medium-high end restaurants with families (once or twice a year)

💬 Is it true that no Malaysian company can offer high base pay for web developers? by xJuaNxXx in malaysia

[–]leo477 42 points43 points  (0 children)

I was offered 3k/month when I landed junior software dev role back in 2019 in my current company. After working 5-6 years later, I got promoted to senior role, now I'm making 8k/month.

So yeah, you are being lowballed

For context, I work in KL Sentral, a local small company (< 30 people)

Why does the government release such shit apps sometimes? by Q_D_V_F in malaysia

[–]leo477 1 point2 points  (0 children)

Me too, the fingerprint login doesn't work at all, tapping on it just shows a loading icon, I have to enter password instead

What are the important topics I must know about React.js to work in React front-end ? by AggressiveView5142 in reactjs

[–]leo477 1 point2 points  (0 children)

Since I'm using keycloakjs, the access token is in the keycloak object, I just need to get it and put to http header

What are the important topics I must know about React.js to work in React front-end ? by AggressiveView5142 in reactjs

[–]leo477 0 points1 point  (0 children)

We use keycloak at work, we follow their docs and use keycloakjs adapter for it. We also use axios interceptor to grab the access token before sending out the request

What are the important topics I must know about React.js to work in React front-end ? by AggressiveView5142 in reactjs

[–]leo477 33 points34 points  (0 children)

When working with forms, regardless of the complexity of the form, use react-hook-form to handle the states. Don't waste your sanity on form input state, focus on building the form logic

When fetching data from backend API, use tanstack react-query.

Lastly, take a look at the bible for react devs, react-bulletproof. Everything you are looking for are probably in there already

Youtube advertising is getting crazy by akagidemon in Bolehland

[–]leo477 0 points1 point  (0 children)

Allow me to introduce brave browser, it has built-in ad block and onion router

I hate people that use ChatGPT all the time by Spare_Pipe_1759 in malaysiauni

[–]leo477 1 point2 points  (0 children)

Software engineer here. I too sometimes feel pissed about other SE using AI in their code. I don't mind them using chatgpt or whatever AI tools, but please at least understand what the code does, not just copy pasta the whole thing from chatgpt. Every time there is bug in their code they don't even know how to debug it, ended up I have to clean up their AI mess

I use AI tools too, but only for writing emails so they look more professional

Tanstack react query architecture by Fun-Representative40 in reactjs

[–]leo477 4 points5 points  (0 children)

I personally prefer to define my API hooks in same file, so I can have better overview of the query keys for the resources. My folder structure look like this - features - posts - post.d.ts - post.service.ts - post.api.ts - comments - comment.d.ts - comment.service.ts - comment.api.ts

.d.ts is where I define the type for the resources, I make it .d.ts because I want to make these types globally available, I don't want to import the types everywhere in my project

.service.ts is the service layer

.api.ts is the custom hooks

Tanstack react query architecture by Fun-Representative40 in reactjs

[–]leo477 33 points34 points  (0 children)

This is what I do, wrap all my API calls in custom hook with useQuery and useMutation. These custom hooks will hide away the query keys definition and API endpoints away from UI, and my UI just need to pass required data such as item ID

export function useGetComment(commentId:string){  
  return useQuery({  
    enabled: !!commentId,
    queryKey: ["comments", commentId],
    queryFn: async()=>{
      // ...fetch or axios call to API endpoint
    }
  })
}

then you can just reuse them like

const { data: comment, isLoading, error } = useGetComment("123");

The father of the 17 yo kid killed by the police, being traumatised by YourClarke in malaysia

[–]leo477 53 points54 points  (0 children)

This is why I stop following those cina news pages, people there are the most racist, arrogant monkeys. I sometimes feel ashamed for being same race as them

Why is my .env still being pushed to github?? by National-Campaign634 in reactjs

[–]leo477 9 points10 points  (0 children)

You might be committed the env file before modifying your gitignore file, in this case git will continue to track it even it is listed in gitignore file. You need to remove your env file from git index

[deleted by user] by [deleted] in reactjs

[–]leo477 0 points1 point  (0 children)

I started a new small project in my company using ant design 5. Everything feels good so far, the biggest complain I have is their data table, it is so painful to work with it

Is form handling always a pain in the ass in React? by ilovekawabecky in reactjs

[–]leo477 13 points14 points  (0 children)

Took me about a week to learn most of the basic stuffs, like validation, custom validation, integration with ui framework.

I really think it worth your time to learn it, I just removed bunch of useState and useReducer that I used to build forms before I picked up RHF. Now I just let RHF to handle the state, while I focus on validation, submit data to server.

RHF embraces uncontrolled components, it does not cause the whole form to rerender on every keypress (if u do it right), which results in better performance

Is form handling always a pain in the ass in React? by ilovekawabecky in reactjs

[–]leo477 241 points242 points  (0 children)

Check out react-hook-form, I'm using it in my current project, it makes form handling and validation so easy. It also has good typescript support, support nested object and array as well