Burak Erdem
Burak Erdem

Reputation: 1

Problem adding html attribute in SWR Mode

In my nuxt application I set the route '/' to swr. But I need to add a class to the html element according to the 'app-theme' cookies. But I can't do this because it's in SWR mode. Is there any way to solve this problem?

I tried this code but found that SWR mode is not enabled.

export default defineNitroPlugin((nitroApp) => {
    nitroApp.hooks.hook('render:html', (htmlContext, {event}) => {
        const cookie = getCookie(event, 'app-theme');
        const theme = cookie === 'dark' ? 'dark' : '';
        
        htmlContext.htmlAttrs.push(`class="${theme}"`);
    });
});

Upvotes: 0

Views: 12

Answers (0)

Related Questions