Mine is that the useState hook is an actual plague on the entire React ecosystem. Regardless of your opinions of React, if you wanna use something then use it right.

  • Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    9 days ago

    Moreso correctness, not security. In the end, your user is shooting themselves in their foot, if they mutate a variable that they shouldn’t, and by making the variable private and only offering a getter, we document that.

    Having said that, there’s also big differences between languages and paradigms, though.
    In object-oriented / garbage-collected languages, you often pass around references to an object into so many places that you need to code defensively versus your own codebase. That’s why getters/setters were taught religiously during the height of OOP.

    In other paradigms, you often just have one place that uses an object and then you can …simply not shoot yourself in the foot there. When you control both the definition and the access, you don’t need to protect yourself from yourself. In particular, you would probably think twice before mutating an object anyways.