#Why do docs store env variables on window when you can get from root loader using useMatches?

1 messages · Page 1 of 1 (latest)

sharp vine
#

I have been pulling env variables from the root loader using useMatches. Is there a reason that official docs put it on the window?

unborn bronze
#

So you don’t need to pass them around

#

I personally prefer to be explicit so pass them as arguments

sharp vine
#

But wouldn't useMatches on root allow you to pull them server side in the component vs needing to wait on the window to be available after render?

unborn bronze
#

Another thing you can do is to set them on window.process.env which will make process.env a thing client side, useful when using libraries that read from process.env directly because on webpack you can use the DefinePlugin to set them

sharp vine
#

Ah

unborn bronze
sharp vine
#

So it is more of a way to avoid have remix specific code to work with env variables and just allow you to use process.env anywhere in your code. If it is server side it pulls from global and client it pulls from window.

#

Not a bad idea