Skip to content

Commit

Permalink
fix: Make JSXStyle return a noop if the registry context is not pro…
Browse files Browse the repository at this point in the history
…vided (#749)
  • Loading branch information
shuding authored Sep 15, 2021
1 parent 4234ed6 commit e5c3842
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/style.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { useLayoutEffect, useContext } from 'react'
import { StyleSheetContext } from './stylesheet-registry'
import { useLayoutEffect } from 'react'
import { useStyleRegistry } from './stylesheet-registry'
import { computeId } from './lib/hash'
export default function JSXStyle(props) {
const registry = useContext(StyleSheetContext)
const registry = useStyleRegistry()

// If `registry` does not exist, we do nothing here.
if (!registry) {
return null
}

if (typeof window === 'undefined') {
registry.add(props)
return null
}

useLayoutEffect(() => {
registry.add(props)
return () => {
registry.remove(props)
}
// props.children can be string[], will be striped since id is identical
}, [props.id, String(props.dynamic)])

return null
}

Expand Down

0 comments on commit e5c3842

Please sign in to comment.