MCPcopy Index your code
hub / github.com/formkit/formkit / FormKitRoot

Function FormKitRoot

packages/react/src/FormKitRoot.ts:14–37  ·  view source on GitHub ↗
(props: { children?: ReactNode })

Source from the content-addressed store, hash-verified

12 * whether a FormKit input is booting in a Document or ShadowRoot.
13 */
14export function FormKitRoot(props: { children?: ReactNode }) {
15 const boundary = useRef<HTMLSpanElement | null>(null)
16 const [root, setRoot] = useState<Document | ShadowRoot | undefined>(undefined)
17
18 useLayoutEffect(() => {
19 const boundaryNode = boundary.current
20 if (!boundaryNode) return
21 const nextRoot = boundaryNode.getRootNode()
22 const isShadowRoot =
23 typeof ShadowRoot !== 'undefined' && nextRoot instanceof ShadowRoot
24 if (isShadowRoot || nextRoot instanceof Document) {
25 setRoot(nextRoot)
26 }
27 }, [])
28
29 if (!root) {
30 return createElement('span', {
31 ref: boundary,
32 style: { display: 'none' },
33 })
34 }
35
36 return createElement(rootSymbol.Provider, { value: root }, props.children)
37}
38
39export { rootSymbol }

Callers

nothing calls this directly

Calls 1

createElementFunction · 0.90

Tested by

no test coverage detected