Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Clear cache on view transition #4311

Open
nojaf opened this issue May 14, 2024 · 0 comments
Open

Clear cache on view transition #4311

nojaf opened this issue May 14, 2024 · 0 comments

Comments

@nojaf
Copy link

nojaf commented May 14, 2024

Hello,

I'm looking for the alternative code in styled-components for

import styled from '@emotion/styled';
import { withEmotionCache } from '@emotion/react';
import { useEffect } from 'react';

const StyledButton = styled.button`
  display: block;
  padding: 4em;
  background-color: red;
  color: white;
`;

const Button = withEmotionCache((props, cache) => {
  useEffect(() => {
    document.addEventListener('astro:before-swap', () => {
      cache.inserted = {};
      cache.registered = {};
      cache.sheet.flush();
    });
  }, []);

  return <StyledButton>My styled button</StyledButton>;
});

export default Button;

When the 'astro:before-swap' event happens my style needs to be triggered.
Is there a way to do this in styled components?

(More context in withastro/astro#11000)

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

No branches or pull requests

1 participant