developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.67k stars 170 forks source link

React Context value is always converted to String #177

Closed broofa closed 4 years ago

broofa commented 4 years ago

[I'm not sure if this is the right project for this, but figured I'd start here since I'm using the htm+preact standalone bundle.]

tl;dr: I'm setting a Context.Provider value as an Array, however in the consumer (functional react component using useContext), it's received as a String.

This codepen illustrates the problem. In both Firefox and Chrome, this renders the following:

Provider sets context as [object Array]
Consumer receives context as [object String]

Edit: As noted in the codepen, this issue (context value getting cast to String) happens regardless of the type being set.

broofa commented 4 years ago

Nevermind. Just figured out this was due to an extra bracket in my template string. "value=${context}}>"

Please don't ask how long I've spent trying to figure this out. 🤣

image