Building with AdonisJS & Inertia #2.6

Creating A Layout

In This Lesson

We'll learn how to create a layout component and apply it to all our pages, the Inertia way.

Created by
@tomgobich
Published

⏳ Chapters

00:00 - Creating Our Layout
03:06 - Using Our Layout
06:10 - Inspecting Our Layout

Join the Discussion 2 comments

Create a free account to join in on the discussion
  1. If we do something like this in react
    ```
    resolve: async (name) => {

    const page = await resolvePageComponent(`../pages/${name}.tsx`, import.meta.glob('../pages/**/*.tsx'))

    page.default.layout = page.default.layout || (page => <MainLayout>{page}</MainLayout>)

    return page

    }
    ```
    We get typescript errors that page is of type unknown, what would be the proper typing for page?

    1
    1. Responding to cubicalprayer712
      @tomgobich

      Hi cubicalprayer712!

      Vladimir kindly left steps on getting this setup in React in the next lesson's comments if you'd like more details, but something like the below should satisfy the needed typing.

      const page = await resolvePageComponent(
        `../pages/${name}.tsx`,
        import.meta.glob('../pages/**/*.tsx'),
      ) as {
        default: ComponentType & { layout?: (page: ReactElement) => ReactElement }
      }
      
      page.default.layout = page.default.layout
      Copied!
      0