How does props program flow work in react js?

Click For Summary
SUMMARY

The discussion focuses on the program flow of props in React.js, specifically through the components App.js and Users.js. The App component imports and renders the Users component three times, passing properties 'name' and 'job' to each instance. The Users component accesses these properties using props.name and props.job, demonstrating the flow of data in React. Additionally, both App and Users are identified as function objects, utilizing arrow function syntax for their definitions.

PREREQUISITES
  • Understanding of React.js component structure
  • Familiarity with JavaScript ES6 arrow functions
  • Basic knowledge of props in React
  • Experience with functional programming concepts
NEXT STEPS
  • Study React.js component lifecycle methods
  • Learn about state management in React using hooks
  • Explore the concept of higher-order components in React
  • Investigate the use of PropTypes for type-checking props
USEFUL FOR

Frontend developers, React.js learners, and anyone looking to understand component-based architecture and data flow in React applications.

shivajikobardan
Messages
637
Reaction score
54
TL;DR
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 16 ·
Replies
16
Views
5K