Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AndrewL64's avatar

Global component in inertia-react

How do I go about adding a global component (e.g. Link) to the following inertia-react's createInertiaApp() method in Laravel 9?

import { Link } from '@inertiajs/inertia-react';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.jsx`, import.meta.glob('./Pages/**/*.jsx')),
    setup({ el, App, props }) {
        return render(<App {...props} />, el);
    },
});
0 likes
6 replies
Sinnbeck's avatar

In react you import whatever you need in each file. What is needed in every single page component?

Sinnbeck's avatar

@AndrewL64 Import them where you need them. React does not have global components :)

import {Link} from '@inertiajs/inertia-react'
AndrewL64's avatar

@Sinnbeck Import them where you need them.

Sad. I guess I'll have to do that for now. Thanks for the help anyway man.

Just a thought, but what if I pass the Link component as a prop from the root App component to the children components? Would that work?

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@AndrewL64 you might be able to do some sort of trick to get that working, but that isnt how react is designed. And using it as a component from prop would most likely be more code than the import, and you would need it in every file

If you are using phpstorm you can just ask it to import it when you type it. Pretty sure vscode has something similar

2 likes
AndrewL64's avatar

@Sinnbeck you might be able to do some sort of trick to get that working, but that isnt how react is designed. And using it as a component from prop would most likely be more code than the import, and you would need it in every file

Makes sense. I guess I'll just stick with manual imports. Thanks again for the help.

Please or to participate in this conversation.