DEV Community

loading...

Discussion on: 7 code smells in your React components

Collapse
sfiquet profile image
Sylvie Fiquet

Hi! I really enjoyed your article. The options pattern will help with a component of mine that didn't feel right.

I think the reducer example needs to be edited though:

  • the dispatch type for selectItem is 'reset', I believe it should be 'selectItem' to match the reducer?
  • shouldn't the case for selectItem do the same thing as the function? isOpen and inputValue won't change on their own. Or am I missing something?
    case "selectItem":
      return {
        ...state,
        isOpen: false,
        inputValue: action.payload.name,
        selectedItem: action.payload
      }
Enter fullscreen mode Exit fullscreen mode
Collapse
awnton profile image
Anton Gunnarsson Author

Thank you Sylvie and good catch! A bit too fast with the copy/paste it seems! :D Updated it now! 🙏