TanStackT
TanStack7mo ago
13 replies
standard-azure

Inline styles

I'm building a whitelabel multi-tenant app that gets the tenant colors from an api before render. I found this hacky solution to inject the theme directly on the head of my root component like this:
function RootComponent() {                    
  const { authState } = Route.useLoaderData() 
  const theme = getTheme(authState)           
                                              
  return (                                    
    <html>                                    
      <head>                                  
        <HeadContent />                       
        <style>{theme}</style>                
      </head>                                 
      <body>         
        <Outlet />                            
        <Scripts />                           
      </body>                                 
    </html>                                   
  )                                           
}                                                                                         

But I was wondering if there was cleaner way using the createFileRoute function, something like this:
head: ({ match }) => {                      
  const { context } = match                 
  const theme = getTheme(context.authState) 
  return {                                  
    styles: [ { content: theme } ],         
  }                                         
}                                         
Was this page helpful?