Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

useStyles effects callback dont called #177

Open
xblj opened this issue Mar 1, 2020 · 1 comment
Open

useStyles effects callback dont called #177

xblj opened this issue Mar 1, 2020 · 1 comment

Comments

@xblj
Copy link

xblj commented Mar 1, 2020

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
Copy link

jameswhf commented Mar 4, 2020

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants