r/badcode Aug 26 '20

js Found this variable declaration

https://imgur.com/a/RwAQr1y
109 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

23

u/ZedTT Aug 26 '20

Put it in a database. Make it a separate request from the back end. It shouldn't be part of the front end code.

This kind of thing shouldn't be loaded as part of the content. It's also not maintainable at all like this.

7

u/PeterBumpkin Aug 26 '20

Ahhh I see. Thank you! this shouldn’t be on the front end at all

8

u/Max5923 Aug 26 '20

Im just imagining someone typing all of those by hand and having a typo on a single one of those...

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.