Re:Redux – Not Dead Yet
by hestefisk on Tuesday April 24, 2018 @11:07PM
(#16918372)
Context to me seems like a sophisticated way of declaring global variables. Might as well do const GLOBALS = { ... } instead of another complex API that has to be loaded.
[ Parent
| on HN ]
It's not, though, any more than dependency injection is "declaring global variables".
The new context API effectively makes variables available globally, but you're still using a separate (explicitly declared) Consumer for each, so you don't have any of the basic issues that go with using a single set of globals.
For a very simple example:
import { UserIdConsumer } from '@/contexts'
const ThisComponent = () => (
<div>
User ID: <UserIdConsumer>{value => value}</UserIdConsumer>
</div>
)
export default ThisComponentNot sure I follow. Where does value come from?