Easy layout implementation #682
Replies: 11 comments 4 replies
-
This is an interesting idea! I don’t know whether it’s within the scope of Blitz, but it’s certainly something we could write docs on. Gatsby used to have something like this, but they removed it in v2 for these reasons. Definitely open to discussion though! |
Beta Was this translation helpful? Give feedback.
-
I am wondering what is the main advantage here? avoiding re-rendering? I think syntactically it is possibly more obtuse and confusing as having the Layout within the Page communicates the structure of the render tree clearly without having to know anything about how next does rendering. Eg. import FooLayout from 'app/layouts/foo-layout'
// I know the following wraps content by looking at this
export default () => <FooLayout><div>Some content</div></FooLayout> import FooLayout from 'app/layouts/foo-layout'
const FooPage = () => <div>Some content</div>
// If I know nothing about the framework how do I know what this means?
FooPage.Layout = FooLayout
export default FooPage |
Beta Was this translation helpful? Give feedback.
-
Right I agree with @ryardley. This was basically the main reason Gatsby removed it, since it’s a weird obfuscation of what your component tree will actually look like, and isn’t how React normally behaves. The only advantage in my eyes is what you mentioned–that it prevents a re-render. I guess it’s a question of whether we feel this is a sufficiently common use-case to build it into Blitz, when it’s already possible without a special implementation. |
Beta Was this translation helpful? Give feedback.
-
There’s a good article on how to achieve this normally with Next (and therefore Blitz), and why you might ever want to do it here: https://adamwathan.me/2019/10/17/persistent-layout-patterns-in-nextjs/ |
Beta Was this translation helpful? Give feedback.
-
Also what happens when you want to add props to your layout? This is easy. import FooLayout from 'app/layouts/foo-layout'
export default () => <FooLayout title="My great page"><div>Some content</div></FooLayout> but would be hard with an export |
Beta Was this translation helpful? Give feedback.
-
Personally I’d say the smaller the Blitz API surface can be, the better. |
Beta Was this translation helpful? Give feedback.
-
@merelinguist Totally agree |
Beta Was this translation helpful? Give feedback.
-
@ryardley @merelinguist Thanks for answering the issue! I do get the point. Probably I hadn't thought about this enough. |
Beta Was this translation helpful? Give feedback.
-
cc/ @flybayer re the layouts folder? |
Beta Was this translation helpful? Give feedback.
-
Good discussion everyone! Currently the Originally I was thinking to basically include Adam's article mentioned above in our docs. But I'm open to adding some type of built in layout support into Blitz since it's so common. But I don't have a good sense of how command persisted layout is needed. @simonedelmann what are you needing persistent layout for? Is it public facing pages like documentation or is it inside an app with a login? For our auth recipe that adds username/password authentication, I've been thinking that recipe will also add |
Beta Was this translation helpful? Give feedback.
-
In my case (basically a SPA) I only have one layout which almost all pages (= all but Login/Register and Error) share. The layout contains some navigation and will contain information based on the current authenticated user (when authentication is finished). I plan to add a search box, therefore I need the persisted layout. |
Beta Was this translation helpful? Give feedback.
-
What do you want and why?
It would be great to have a simple mechanism to import a layout from /app/layouts folder.
I would prefer something like this:
If it is not possible to do
export Layout = ...
, an alternative:Possible implementation(s)
This is how I use the layout in a project right now:
// _app.js
Suggested improvements:
AppProps
could be build into blitz.Component.Layout
but a separatedLayout
parameterThis could end in an _app.js like this for the end user:
Beta Was this translation helpful? Give feedback.
All reactions