5 ms·
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
by hestefisk 9y ago
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.
- eropple 9y agoIt's not, though, any more than dependency injection is "declaring global variables".
- crooked-v 9y agoThe 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 ThisComponent