T
TanStack•2y ago
generous-apricot

mapping through data

Do i have to use a set state variable to map through or why can i not direclty map through data?
No description
16 Replies
generous-apricot
generous-apricotOP•2y ago
the error i get is 'data is possible undefined' and parameter 'item' has an 'any' type
foreign-sapphire
foreign-sapphire•2y ago
This was answered recently: https://discord.com/channels/719702312431386674/1179255735251644477/1179305475196600320 If you don't care to render anything, then you can also just optional chain that map
generous-apricot
generous-apricotOP•2y ago
@troywoy thanks still a little confused but that helps
foreign-sapphire
foreign-sapphire•2y ago
data?.map((item, i) => { ... }
generous-apricot
generous-apricotOP•2y ago
getting property map does not exist on type subscription that is what i did
foreign-sapphire
foreign-sapphire•2y ago
Is this query returning an array or an object
generous-apricot
generous-apricotOP•2y ago
No description
foreign-sapphire
foreign-sapphire•2y ago
Did you mean to make it Promsie<ReadonlyArray<Subscription>>?
generous-apricot
generous-apricotOP•2y ago
No, where is it being made. readonly?
foreign-sapphire
foreign-sapphire•2y ago
Well readonly doesn't matter, I just prefer it. Changing line 12 from Promise<Subscription> to Promise<Array<Subscription>>
generous-apricot
generous-apricotOP•2y ago
That takes the error away! thank you Now there is a different error but i can resolve this
foreign-sapphire
foreign-sapphire•2y ago
The fun of developing in typescript lol
generous-apricot
generous-apricotOP•2y ago
Still newer to it coming from python
foreign-sapphire
foreign-sapphire•2y ago
Been using it for 2 years and still consider myself new
generous-apricot
generous-apricotOP•2y ago
😂 @troywoy I have one more question maybe you can answer If i am mapping threw is there a way to style the "title" different to have a different bg color for each
foreign-sapphire
foreign-sapphire•2y ago
You can do that however you want. Try adding style, or className would probably be better, onto your SubscriptionCard

Did you find this page helpful?