It depends on what you are trying to achieve. If the goal is to be able to retrieve the value and not listen to its setState event, then this approach would work just fine. Do not that since you are setting the value on the window, this value can be read by other scripts that are not on your website. For example when used with iFrames. Make sure that the data you are setting does not contain sensitive information.
If what you are trying to achieve would also involve knowing when the state changes, then I would suggest you look into using an event driven state update. In this case you would set an event emitter that you can subscribe in order to get a callback when the state changes. Have a look on this for inspiration.