data becomes undefined when it is not undefined
I have a component which has some props.
When I console log the props they work fine but when I access any fields of the props it becomes undefined
16 Replies
Looks like you have nested objects.
data.data.whatever
I changes the function signature to this and it worked
why did this happen?
data.data.uid
Because you’re now destructuring the inner
data
object from props. So now you can reference just data.whatever
If you don’t destructure the arguments then it’s what Barry and I said abovethis happens if i dont destructure it
because I declared the type I think
I think you’re confusing yourself potentially by calling props data
thats just your ts type breaking it
data.data is of SentReceiptType
It’s not generally easy to think about
data.data
it’s far easier to think about props.data
imo but yes the type is wrongdata is not
you're breaking it
oh I see props is not data, got it
Thanks!
You can call it whatever you want but personally I don’t like calling the top level object the same thing as the nested property. I find it hard to think about the structure when I do that
Alternatively if you only have a single top level property in the props object you could make your life easier by spreading it and flattening it so you don’t have to think about a nested object in props, instead you just have a bunch of top-level properties
Is probably how I would name it.
Something along those lines
Never go generic
Yeah any specific name is typically better than
data
100% agreewill do that!
got it thanks!
😂 thats only thing that came to my mind