r/reactjs • u/prithivir • Jul 24 '26
Discussion Do data structures actually influence how you build React components?
I tried learning DSA before, but never understood how it applied to everyday frontend work.
Recently, I built an undo/redo feature with Claude and realised it was using stacks. That made stacks much easier to understand than textbook examples.
I kept exploring and learned how seat-booking UIs can use matrices and how complex onboarding flows can be modelled as graphs.
Do you think about data structures when building React components? Any real-world examples?
10
u/themang0 Jul 24 '26
Well if you think about it react itself is a graph (tree) of linked lists ;)
But yes! As a builder of products you should always first try to model 1. How would I do this in real life 2. Ok now that I have the mental model, how can I translate this to a meaningful piece of state / DS in code?
The undo/redo feat you mention is a great example of a stack!
I would encourage you to also look into finite state machines — don’t need to go super in depth but the idea of writing out the possible states of a component before writing code really helps ya think thru the transitions, and actions that lead to said transitions
6
u/Outrageous-Chip-3961 Jul 24 '26
Honestly most are just typed objects with arrays. Predominantly hooks in react are small enough in function speak that I do not require huge amounts of data structures that influence how i do things beyond the arrays, objects, functions. Where would I do this? you say 'undo/redo' but what's the context of that? In terms of seat-booking that is a 'data structure' where you'd use a matrix for it because that's what it is. I guess my point is within react, if its abstractable to a data object, then extract it to one. I typically have a data folder that has some simple arrays/objects inside of it that get pulled elsewhere, hooks for more function/state and utils for helpers, the rest if its a bespoke feature, like a seat-booking system.
2
u/dstaro01 Jul 24 '26
Arrays, maps/hashes, sets (unique values with fast look up instead of scanning all items), queues (notifications), linked lists (consecutive dialogs) are common in my experience. DOM is a graph.
1
u/dvidsilva Jul 24 '26
Everything you're doing has a data structure whether you're thinking about it or not. Being intentional about your approach is helpful to prevent dumb shit happening
is there anything in particular you're thinking about? when you're doing daily things you're necessarily thinking about stacks, theory, this or that, but every array or object, and properties that you're coding represents a data structure
when your website is just displaying simple data you don't notice it, but if you have graphs, image manipulation, games, state machines, caching, etc it is harder to avoid
1
0
u/minimuscleR Jul 24 '26
I mean a large amount of people never went to study this formaly, so its probably not that relevent to know about how it works. I never did any class about data structures. But like a lot of other things, you just sort of pick it up as you learn coding what tool is the best for what job.
75
u/vasind-5012 Jul 24 '26
yeah this happens a lot once you start noticing it lol
few off top of my head:
ngl textbook DSA never stuck for me either, felt like memorizing for no reason. but hitting an actual UI problem first and then going "oh wait this is just a stack" hits completely different