logoalt Hacker News

torginusyesterday at 10:22 PM2 repliesview on HN

This creates the drill-down issue we see with React props where we have to pass objects around in the call chain just so that somewhere down the line we can use it.

React gets around this with the context hook and which you can access implicitly if it has been injected at a higher level.

Do you know if Zig supports something of the sort?


Replies

throwaway17_17today at 2:21 AM

I think (and I’m not a Zig user at anything above a hobbyist level) based on what the developers have discussed publically:

React has a ‘roughly’ functional slant to the way it does things and so needs to provide a special case ‘hook’ for a certain type of context object. Zig however is an imperative language that allows for global state (and mutable global state for that matter), which means that there is always a way to access global variable, no hook required. On the other hand, I am relatively certain (almost 100% to be honest) there can not be a context/IO , or any data/variable, passed into a function higher up the call stack and have that propagate to the lower level via implicit inclusion.

messeyesterday at 10:27 PM

It doesn't and likely never will.

This has been a non-issue for years with Allocator. I fail to see why it will be a problem with IO.

show 2 replies