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

demonz's avatar

usePage or props ?

Hello , I am confused at which one is better

const { courses } = usePage.props();

or

const { courses } = props;

I am using react , laravel and inertia js

0 likes
5 replies
Sinnbeck's avatar

If you are inside some component deep down you can use const { courses } = usePage.props; instead of passing down the data through all components

If you are in the page component you can just get it in the constructor

export default function Welcome({cources}) {
3 likes
azimidev's avatar

There is no better one, Page actually has all the information you need using HandleInertiaRequest.php so you need that for information related to pages, user authentication and so on. Why do you need to store courses in that? I don't know maybe because you want that on all available pages? if so then you don't need props which I think it'll come from your response. Don't do multiple requests to get the same results.

demonz's avatar

@azimidev no I have a react component called index which views the course information , so if I passed $course in inertia render , which is better to access it ? usePage.props; or from props; both does the samething ..

azimidev's avatar

@demonz they are not the same thing. they both have the data because you already passed it through. you should re-read what I mentioned above.

Please or to participate in this conversation.