Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix props is undefined in extended Inertia's Head #1433

Merged
merged 1 commit into from
Feb 14, 2023

Conversation

tykatyk
Copy link

@tykatyk tykatyk commented Feb 5, 2023

According to the documentation you can extend Inertia's Head component.
Here is the example from the docs.

// AppHead.js
import { Head } from '@inertiajs/react'

const Site = ({ title, children }) => {
  return (
    <Head>
      <title>{title ? `${title} - My App` : 'My App'}</title>
      {children}
    </Head>
  )
}

export default Site

And then use that extended component like this:

import AppHead from './AppHead'

<AppHead title="About">

The problem
As you can see AppHead can receive children. But if you try to pass more than one child to that extended Head component, you will get an error in the console: TypeError: e.props is undefined

Here is the example of such usage that throws an error

import AppHead from "./AppHead";

export default function HomePage() {
    return (
        <>
            <AppHead title="Your page title">
                <meta name="description" content="Your page description" />
                <link rel="stylesheet" href="./styles.css" />
            </AppHead>
            <div>Some content here</div>
        </>
    );
}

This pull request fixes the problem of multiple children in extended Head component

@jessarcher
Copy link
Member

Thank you! I've replicated the issue, confirmed this fixes it, and confirmed that it doesn't now break when there is only a single child 👍

@jessarcher jessarcher merged commit d2ff503 into inertiajs:master Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants