T
TanStack•2y ago
conscious-sapphire

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
conscious-sapphire
conscious-sapphireOP•2y ago
the error i get is 'data is possible undefined' and parameter 'item' has an 'any' type
continuing-cyan
continuing-cyan•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
conscious-sapphire
conscious-sapphireOP•2y ago
@troywoy thanks still a little confused but that helps
continuing-cyan
continuing-cyan•2y ago
data?.map((item, i) => { ... }
conscious-sapphire
conscious-sapphireOP•2y ago
getting property map does not exist on type subscription that is what i did
continuing-cyan
continuing-cyan•2y ago
Is this query returning an array or an object
conscious-sapphire
conscious-sapphireOP•2y ago
No description
continuing-cyan
continuing-cyan•2y ago
Did you mean to make it Promsie<ReadonlyArray<Subscription>>?
conscious-sapphire
conscious-sapphireOP•2y ago
No, where is it being made. readonly?
continuing-cyan
continuing-cyan•2y ago
Well readonly doesn't matter, I just prefer it. Changing line 12 from Promise<Subscription> to Promise<Array<Subscription>>
conscious-sapphire
conscious-sapphireOP•2y ago
That takes the error away! thank you Now there is a different error but i can resolve this
continuing-cyan
continuing-cyan•2y ago
The fun of developing in typescript lol
conscious-sapphire
conscious-sapphireOP•2y ago
Still newer to it coming from python
continuing-cyan
continuing-cyan•2y ago
Been using it for 2 years and still consider myself new
conscious-sapphire
conscious-sapphireOP•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
continuing-cyan
continuing-cyan•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?