kriasoft / isomorphic-style-loader

CSS style loader for Webpack that is optimized for isomorphic (universal) web apps.
https://reactstarter.com
MIT License
1.27k stars 144 forks source link

useStyles effects callback dont called #177

Open xblj opened 4 years ago

xblj commented 4 years ago

switch route style will not be removed

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()
  }
}
jameswhf commented 4 years ago

isBrowser should be checked in runtime, or let user define isBrowser themselves