JavaScript How does props program flow work in react js?

AI Thread Summary
The discussion revolves around understanding the flow of a React application, specifically the interaction between the App and Users components. The App.js file serves as the main entry point, where it renders the Users component multiple times, each time passing different properties for name and job. The Users component receives these properties through props and displays them accordingly. Participants clarify that both App and Users are function objects, utilizing arrow function syntax. The conversation emphasizes the importance of recognizing how components communicate through props and how the structure of the code facilitates the rendering of user information in a React application.
shivajikobardan
Messages
637
Reaction score
54
TL;DR Summary
How does props program flow work in react js?
App.js:

JavaScript:
import React from 'react'
import Helloworld from './components/HelloWorld';
import Users from "./components/Users";

const App = () => {
  return (
    <div>
      <h1>List of Users</h1>
      <Users name="Zino Emi" job="Developer" />
      <Users name="Lionel Messi" job="Web Developer" />
      <Users name="Cristiano Ronaldo" job="Software Engineer" />

    </div>
  );
};export default App;

src/components/Users.js:

JavaScript:
import React from 'react'

const Users = (props) => {
  return (
    <div>
      <div className="user">
        <h2>Name: {props.name}</h2>
        <h3>Job:{props.job}</h3>
      </div>
    </div>
  )
}

export default Users

I'm not understanding the program flow here. What happens first then what? React is really confusing man.

Can anyone help me build a mental model of it?

Output:
BSZmoL48xmkMy0qH27SriEjV467SkN8PO1mEt_X2zIr70yNmmQ.png
 
Technology news on Phys.org
1) Start with App.js
2) It returns Users component.
3) Inside Users component we pass properties name and job.
4) Inside Users.js we access it using props.name and props.job.
A figure that helped me

qEiARSBnn7sus-etImyqDuhXtZwY_S9NNjiv8l6O1aY2_cXS5w.png
 
I'll take a shot at this, although it's been a long time since I've done anything in JavaScript and I don't know React.js at all.
shivajikobardan said:
1) Start with App.js
2) It returns Users component.
3) Inside Users component we pass properties name and job.
4) Inside Users.js we access it using props.name and props.job.
Your analysis looks more-or-less correct to me. What I would add is to describe App and Users as function objects, AKA lambdas.
The => notation in your code suggests to me that these are function objects.
Code:
const App = () => { <snip>

const Users = (props) => { <snip>
App.js imports a function object named Users, and defines a function object named App. The App function object takes no parameters and returns an HTML div.

Inside the div that is returned are calls to the Users function object. This function object takes one parameter, a list or tuple whose members are name and job. This function object also returns an HTML div. The HTML div that App returns lists Users three times, with each instance being a call to this function object, passing the relevant tuple/list in the call.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
1
Views
2K
Replies
2
Views
2K
Replies
8
Views
2K
Replies
10
Views
3K
Replies
16
Views
4K
Back
Top