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

boyjarv's avatar

Loop through $users in React

At the moment, I have set an array [1,2,3,4] as you can see below:

{[1,2,3,4].map((userId) => {
                return this.user.id !== userId ? <button key={userId} onClick={() => this.callTo(userId)}>Call {userId}		</button> : null;
            })}

I am passing $users through from my Laravel app, I would like to know how to loop through $users and pull the ID and Name into react?

Thanks

0 likes
6 replies
boyjarv's avatar

I think I need to pass my variable through as a json object so I can loop through it using .map()

How can I pass my variable through as a JSON object into the react file?

boyjarv's avatar

Thanks Sti3bas, I am just now trying to figure out how to pass it to my react component, I know I nee dto use .map() when I get my JSON object in there

Please or to participate in this conversation.