5 ms·
Nothing. We know it's messy, but React doesn't really provide a better way of doing this. Context is barely mentioned in the docs, "not recommended" by the dev
by richthegeek 10y ago
Nothing. We know it's messy, but React doesn't really provide a better way of doing this.
Context is barely mentioned in the docs, "not recommended" by the devs. Redux is incredibly verbose and overcomplicated. Passing "global" things down in props is just madness (if everything needs it).
Personally I use context, or a singleton (which is just a hidden global really). It's naughty, but usually required for one or two things per application.
FP folks aren't sages hiding in caves who we all wait to come down from the mountains once a year with their crusty wisdom...
- ctvo 10y agoPassing data via props has never been a problem for me. It's explicit, the chain of dependencies explicit, the data flows in one direction, and components can still be dumb while letting us push the glue layer all the way to the top. No one has ever approached that code and been confused or had issues tracking down bugs in my experience. I agree it's ugly. I've found it triggers the same sense in a lot of developers that make them over-abstract code to achieve DRY at the expense of simplicity (this is just an observation, I don't have an opinion on if it's good or bad!).
- neiltwist 10y agoReact doesn't, but JS perhaps does. A lot of my code has to be mounted in separate root components and it's not allowed to be a SPA. In this instance, it was convenient to use event listeners, though it's very similar to calling a global.
- platz 10y agook, well "Nothing" means folks go OP route, globals everywhere—if that's expected than I guess there's no problem. I did not think globals everywhere was what React expected users to implement.