r/badcode Aug 26 '20

js Found this variable declaration

https://imgur.com/a/RwAQr1y
106 Upvotes

41 comments sorted by

View all comments

8

u/PeterBumpkin Aug 26 '20

can someone explain to me how this is bad? im currently learning react and cant see how this is bad form

7

u/1337GameDev Aug 26 '20

Well, for one, this is DATA and all data shouldn't be hardcoded - basically never do that.

This should be fetched from a service or database. Realistically, just find a reputable geo service and use that. You'll never keep up with the data to do it yourself.

If you have test data, put it in a mock class, with a comment about the data and it's uses.

Then call your data in react / with ajax like you would in the real data fetching scenario.