How to implement styled-components #382
alexis-piquet
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi dear community!!!
Today I will give you an exemple of styled-components implementation in your awesome Nextron Application 🚀
Install
So first of all install the library:
Compilation
Once its installed add ts files in your
tsconfig.json
under therenderer
directory, which one used for your NextJs part.(The following example contains only representative files, don't forget to keep your existing declarations.)
Initialize it on the Server Side
Create
orEdit
your_document.tsx
in yourpages
directory`.I've a path in the renderer named
styles
and I usets-alias
to import files, here I've a path likestyles/index.ts
.I'll give you an example of it in the next step. Don't panic !!!
Ok fine, you have done the half part of the implementation, continue you have pretty much finish it 💪🏽
Creation of a Global Layout
So now we are able to create our
GlobalLayout
component to define a .... 🎉 .... global layout... Well, you got it!Create
orEdit
your_app.tsx
in yourpages
directory`.So as you can see I use the
ThemeProvider
fromstyled-components
to apply my default theme, after that, I define earlier<Component {...pageProps} />
the<GlobalLayout />
.Now, let's go to the
styles/index.ts
pathWe can find in:
GlobalLayout
componentsBody
, our first styled-component used in the_document.tsx
Don't forget, you will be able to add variables in your styles and play with props, it's the Power of (Love)
styled-components
.Congrats you have implemented it, and I'm pretty sure, you will rock with it now! May the force be with you! 🎉
Don't hesitate to give me feedback ❤️
I wish you happy coding days!!!! 😘
Beta Was this translation helpful? Give feedback.
All reactions