Reputation: 1209
I downloaded html css template and trying to integrate in "nextjs". What is difference between "_app.js" and "document.js"? where should i use/include "css, js" files? either in "_app.js" or inside "document.js" ?
Upvotes: 1
Views: 643
Reputation: 3386
As nextJS docs specify related to _app.js
:
Next.js uses the App component to initialize pages. You can override it and control the page initialization and:
- Persist layouts between page changes
- Keeping state when navigating pages
- Custom error handling using componentDidCatch
- Inject additional data into pages
- Add global CSS
Next page of the docs also specify that _document.js
is:
A custom Document can update the and tags used to render a Page. This file is only rendered on the server, so event handlers like onClick cannot be used in _document.
So basically your global css should go in App.js. However if you need to import certain CDN styles for some libraries I suppose you can do that here as well (but you should probably consider using just _app.js
for this as well as it can be seen in this example)
Regarding the JS question as wikipedia states:
Next.js is an open-source web development framework created by Vercel enabling React-based web applications with server-side rendering and generating static websites.
So basically you should import React components where you need them, but I would recommend you to follow a tutorial if you need to learn more about React (There are a lot of beginner NextJS tutorials that can cover this).
Upvotes: 2