vercel/styled-jsx

Instance-based API instead of global singleton

开放

#64 创建于 2016年12月30日

 (6 条评论) (2 个反应) (0 位负责人)JavaScript (310 个派生)batch import
enhancementhelp wanted

仓库指标

星标
 (7,547 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

I think it would be nice if styled-jsx had a non-singleton interface.

The main use case I've found where a global singleton is problematic is related to rendering within iframes. In short, styles from components rendered within a iframe get rendered outside the iframe, preventing the styles from reaching inside the iframe.

The common pattern to solve this is to rely on React context to share instances, which allow the instance to be overridden within an iframe by overriding context. Then styles from components within a given iframe will be rendered within the iframe using its own instance.

This is somewhat uncommon use case, but creating a singleton interface from an instance is straightforward whereas going the reverse direction is much more difficult. I think making separate packages for the core and singleton interface would not add too much additional complexity or maintenance effort. I'd be happy to work on a PR, otherwise feel free to close this issue.

贡献者指南