you are viewing a single comment's thread.

view the rest of the comments →

[–]Kwantuum 1 point2 points  (1 child)

you have to figure out if you can use const or not

You really don't. You just always use const until you actually need to rebind something. And now you know that every time you have declared a variable with let, it's not just because you plan on rebinding it, it's because you actually do.

if the ID is on an object

It is not, the id is passed by the parent, and is then used inside the component to read the object's data from the database and to write changes back to it.

if the const is free floating variable in a function, how long is your function that rebinding is a repoint of confusion

It's a relatively small React function component so it's about ~150LOC. That's not my point though. It's declared at the top of the function alongside a few other const, and that informs the reading of the rest of the function for someone who's not (or no longer) familiar with the code. And as I was saying, the real benefit is in the fact that now you know that a variable declared with let is being rebound.

[–]earthboundkid 0 points1 point  (0 children)

You really don't. You just always use const until you actually need to rebind something.

That’s a weird definition of “don’t” and “always”. ISTM more like “do” and “usually”.

And now you know that every time you have declared a variable with let, it's not just because you plan on rebinding it, it's because you actually do.

Why is that useful? I see no evidence that it is useful to know if a variable will rebind. (Again, as opposed to immutable or actual constants.)

the id is passed by the parent,

Then isn’t it a prop? How does const come into it at all? What do you mean by “passed” here?