function useStyles(...styles) {
const { insertCss } = useContext(StyleContext)
if (!insertCss) throw new Error('Please provide "insertCss" function by StyleContext.Provider')
const runEffect = () => {
const removeCss = insertCss(...styles)
return () => {
setTimeout(removeCss, 0) // It is not called in strict mode
}
}
if (isBrowser) { // will get undefined in strict mode
useEffect(runEffect, [])
} else {
runEffect()
}
}
switch route style will not be removed