Code Monkey home page Code Monkey logo

Comments (9)

mmmeff avatar mmmeff commented on April 29, 2024 3

@dlindenkreuz Yup! A top-level component would solve many issues at once with Next - it seems to be a fairly severe limitation in the framework at the moment, of which the impact is only marginally mitigated by the inclusion of next/head

from next.js.

krazyjakee avatar krazyjakee commented on April 29, 2024 2

@rauchg this can't be solved if the layout is is remounted with every navigation right? That can't be an acceptable solution to this problem.

Unless I'm missing something. How can the layouts ensure only the child components are remounted, keeping the layout intact?

from next.js.

kafkahw avatar kafkahw commented on April 29, 2024 2

@krazyjakee here's my guess.
The reconciliation process in react will handle it. It detects the difference between two react trees and if the component is the same it'll skip remounting or re-rendering if there's no props/state changes. That way if all routes are using the same top-level component, there won't be a top-level remount if you switch routes.

from next.js.

nodegin avatar nodegin commented on April 29, 2024 1

try to create a components folder and place your items inside

from next.js.

nkzawa avatar nkzawa commented on April 29, 2024

related: #50

from next.js.

dlindenkreuz avatar dlindenkreuz commented on April 29, 2024

@mmmeff Reusable components that are not relevant to the router can reside outside the pages directory. Check out the examples [1] [2].

from next.js.

mmmeff avatar mmmeff commented on April 29, 2024

@dlindenkreuz @nodegin I believe you may have misinterpreted my question.

What I'm asking for is not how to split components out, but rather how I can avoid adding the same components to every single page if they are shared layout elements, such as a page's navigation bar, footer, etc.

I've implemented the following example of a workaround I have for now and pushed it here: https://github.com/mmmeff/nextjs-page-template-example

It also shows how you can apply a CSS reset across your entire application without needing to require('glamor/reset') on every page.

from next.js.

dlindenkreuz avatar dlindenkreuz commented on April 29, 2024

@mmmeff Point taken! I'm currently discussing this with @ericf in issue #50 and suggested a modifiable top-level App component in #88. This would also solve your problem, right?

from next.js.

rauchg avatar rauchg commented on April 29, 2024

For reference to those who find this issue:

  • Top level components are solved by wrapping in HOC (see layout examples inside ./examples)
  • For SSR output, you can now supply a custom <Document /> (see README)

from next.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.