import { ReactNode, useRef, useState } from 'react' import { StyleSheetManager } from 'styled-components' import React from 'react' export const MainComponentWrapper = ({ children }: { children: ReactNode }) => { const [ref, setRef] = useState() const styleRef = useRef() const [cssIsInjected, setCssIsInjected] = useState(false) if (styleRef.current) { styleRef.current.onload = () => { setCssIsInjected(true) } styleRef.current.onerror = () => { // if we don't have any css file (if you use styled components only) setCssIsInjected(true) } } return (
setRef(newRef)}> {ref && cssIsInjected && ( <> {children} )}
) }