React Store State Inconsistency Due to Syntax

Inconsistent syntax in a #React project almost cost me hours of debugging. In store.js, I used set-people, while in Home.jsx, I used set_people. It took a while to catch it. The problems is, after changing both to set_people, the store is now inconsistent since other cases in this switch statement use an underscore. I may change all to an underscore to keep them the same. This seems to be more common among developers than the dash when using storeReducer, despite camel case being most recommended in #JavaScript in general.

  • No alternative text description for this image

It would have been more meaningful if you use the names without "set-" or "set_"

This is why I try to make my types an actual type, even in odd situations where I cannot use an enum. When I was training new developers who needed help finding a bug, I'd start with asking if they thought it was a logic error or a typo -- they quickly learned the "did you plug it in" bug types become more common the more skilled you become with the language - or the "job" at hand. And by keeping this in mind, you can find a good amount of issues, quicker than assuming any/all typos would fail to compile.

Like
Reply

“set-filteredFavorites” is actually your “set-favorites” here what you have in “set-favorites” is really an “add-favorite” case Don’t just change to camel case because JS recommends it - make your own decision based on the current codebase and your team, there may be a reason!

Like
Reply

Short and efficient 😁 Use variables in sperate file export and use , export const setPeople="set_people" case setPeople: 😊

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories