valotas/preact-context

Question: Tag name

mendrik opened this issue · 2 comments

Hi,

is there a way to change the tag name of Context.Provider? Now it generates <span> which results oftentimes in invalid markup.

It would also be nice if the props would extends some sort of HTMLAttributes, so one could use that wrapper to add some classes or other valid html attributes to it.
Just to avoid unnecessary div-soup.

Cheers

Hi @mendrik,

the span will only be used as a wrapper if you define many children as to the Provider. The reason for that is that preact does not support fragments yet. I would suggest to use the Provider with just one child. This will be returned as is and therefore you can define whatever attributes you might want:

<Provider>
  <div className="not-a-span">This div will not get wrapped into a span</div>
</Provider>

Hope that helps

thank you that solved my issue entirely!