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

Sprites can also be put in Layouts #136

Open
vvo opened this issue Mar 20, 2020 · 0 comments
Open

Sprites can also be put in Layouts #136

vvo opened this issue Mar 20, 2020 · 0 comments

Comments

@vvo
Copy link

vvo commented Mar 20, 2020

Hi there, since I wanted to have different layouts in my application, I did not want to have _document.jsx host the sprite directly and wondered if it was possible. And it seems to be working, so I am mostly curious about why the documentation states to put it in _document only? (open question).

For example, this works great:

pages/dashboard.jsx

import React from "react";
import AppLayout from "../lib/AppLayout.jsx"

export default function DashboardPage() {
  return (
    <AppLayout>
      <div dangerouslySetInnerHTML={{ __html: spriteContent }} />
      <div>Dashboard</div>
    </AppLayout>
  );
}

lib/AppLayout.jsx

import sprite from 'svg-sprite-loader/runtime/sprite.build';
const spriteContent = sprite.stringify();

export default function AppLayout({ children }) {
  return (
    <>
      <div dangerouslySetInnerHTML={{ __html: spriteContent }} />
      {children}
    </>
  );
}

I find it nice in my usecase because it does not requires getInitialProps nor does it adds the sprite to the whole document on all pages. Just on the ones I need it.

Should we update the documentation to add this possibility? Or is it a bad idea because it could fail in some cases? Let me know :)

PS: thanks for the library!

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