Hacker News new | past | comments | ask | show | jobs | submit login

> Save the global components off as global variables and just use them ... When my ActivityIndicator component mounts, it saves itself off to a global. Any code can import busy and run busy.start() and busy.stop().

What is the story that FP folks need to tell here, so that people don't do things like this?




The big bugbear is global, mutable state. Global immutable state is not nearly as much of a big deal. Local mutable state, likewise.

Once that global immutable state turns out to be less than immutable (e.g you introduce the ability to change program configuration at runtime), you should look for an efficient way of do DI, which in functional programming just means "how do I pass the same first argument to a lot of functions at the same time". The Reader monad is probably the most archetypally FP approach to the problem.


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...


Passing 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!).


React 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.


ok, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: