Hot answers tagged

6 votes
Accepted

Take postcodes and get the Lat long information from them

The code could be improved with a few tweaks, but it's not bad, and the overall structure looks just fine to me. Error handling is in the wrong place Some of your route handler are ...
user avatar
5 votes

Take postcodes and get the Lat long information from them

Test case structure It doesn't seem like the code totally "lacked effort and structure" but the structure, at least of the test cases, could be better. Since all three ...
user avatar
4 votes
Accepted

How do I refactor this fetch request?

Let me share my async await solution for that: Because Your fetch function is pretty similar till the res.text(), I would ...
user avatar
  • 199
4 votes
Accepted

Display and search through a JSON's items in Vue.js

Overall the code looks fine. There aren't any drastic changes I would advise - just mostly a few simplifications. As far as the design goes it looks good, though it may be wise to add a spinner icon ...
user avatar
3 votes
Accepted

A React - Typescript custom hook for any request (GET, POST, PUT, DELETE) to my back end

The biggest part is that the code works and it looks okay. I only have a few concerns about unnecessary rerenders and inconsistent UI because of inaccurate status state. Below are a few minor things I'...
user avatar
  • 146
2 votes
Accepted

Disabling a form button while there's an http request running

Yes, your approach looks correct to me. I also had faced similar issues earlier in my project (before hooks were introduced) and had used setState for a boolean variable to enable and disable the ...
user avatar
2 votes
Accepted

Try-catch-finally snippet

Refactoring to DRY Code In order to avoid repetition, we could create a couple of reusable functions to enable your functions to all use the same pattern. The pattern: start loading await operation ...
user avatar
  • 13.8k
2 votes

Idomatic way to ignore `finally` block after cancelling network request

Ignore the warning. React gives a warning when you setState after unmount because it indicates a memory leak (in this case, the lingering network request, if not canceled). If the network request ...
user avatar
  • 121
1 vote

Upload multiple images using react and axios

Given that there are a lot of files (5,000), I'd certainly recommend batching the upload process for many reasons; user experience being one of them. With the help of ...
user avatar
1 vote

How to deal with nested callbacks in a clean way?

You can use the async/await syntax, its purpose is exactly cleaning up nested callbacks like this.
user avatar
1 vote
Accepted

JavaScript that deletes everything inside a folder on Box.com

Am I using async/await properly and following best practices? Given how you responded to your own question #1 (i.e. "A: ...
user avatar
1 vote
Accepted

Access token regeneration for Axios requests

General Thoughts I haven't used the paypal API before but did obtain credentials and ran the code. I don't see much that would improve the logic to fetch the token but do see small improvements that ...
user avatar
1 vote

Getting data from API every x seconds and store it in a database

Quickly overviewing the code - it would work. If you are into a more readable approach, I may have just a few (minor) comments: Declare fetchItems as ...
user avatar
  • 111
1 vote

multiple api calls through promise

First of all, putting all your code in the props of your JSX is making it unreadable. Extract this into a function, and have your JSX reference that instead. Next, for debugging, I would recommend ...
user avatar
  • 24.8k
1 vote
Accepted

Idomatic way to ignore `finally` block after cancelling network request

Finally only for unconditional execution I am not a React user, and as such I may be missing something unique to the React way. It seams very strange that you use a ...
user avatar
  • 20.2k
1 vote

Cancelling ongoing http requests when next one is started - web app search feature

You can rewritte this piece of code: ...
user avatar
  • 2,283
1 vote

Fetching data from API in JavaScript

It can be done in many ways based on your use case & code structure, but i feel this can be optimal way of structuring. api/services/index.js ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible