Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
Why does props in props.functionName only need to be called sometimes?

In react, specifically referencing the hooks/functional paradigm, when do you need to use props.functionName? As far as I can tell, if the functions are named the same, you can omit props as follows:

Parent.js

...
<Child functionName={functionName}/>
...

Child.js

...
functionName();
...

However, if the name changes, props must be referenced as follows:

Parent.js

...
<Child otherName={functionName}/>
...

Child.js

...
props.otherName();
...

Am I correct? If so, why use the second design pattern? (Perhaps just to call out that the function comes from a parent and isn't defined at the child level. Or maybe some other reason?)

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

No. The name you use depends entirely on how the child component processes the props it is passed. How the parent component determines what value to pass is completely irrelevant.

If the props are placed in a variable named props then you need to access them through the object stored in the variable.

const Child = (props) => {
    props.functionName();
    ...
}

If the first argument is destructured, then each property is stored in its own variable.

const Child = ({functionName}) => {
    functionName();
    ...
}

If the value is copied to another variable inside the component then you can also use the variable it was copied to.

const Child = (props) => {
    const functionName = props.functionName();
    functionName();
    ...
}
about 4 years ago · Juan Pablo Isaza Report

0

False, It is Destructuring Props in React;

Destructuring is a convenient way of extracting multiple values from data stored in (possibly nested) objects and Arrays

props is an object so we can use the Destructuring

Destructuring gives access to the use of props in a more readable format and discards the need for props for every property.

<Child functionName={functionName}  name={name}/>;
const child = (props)=>{
    // you need to write props.functionName
    props.functionName();
    const thisName = props.name
};

const child =({functionName,name})=>{
    // you dont need to write *props.*
    functionName();
    const thisName = name 
};
about 4 years ago · Juan Pablo Isaza Report

0

When interfacing with a child component, the name that you use for something in your parent component may be different from the prop that the child component requires.

Just for example, say that your parent component has something to do with school, and you have:

const [studentId, setStudentId] = useState();
const [parentId, setParentId] = useState();

But you also have a child component for students that expects an id prop. Then, to pass down the studentId to it, you'd do:

<Student id={studentId} />

And in that child component, you'd reference it by doing props.id.

You wouldn't want to do

const [id, setId] = useState();

in the parent component, and then

<Student id={id} />

when passing it down because then it wouldn't be clear in the parent component which ID that stateful value referred to - you'd probably have to add a comment.

If so, why use the second design pattern?

Sometimes, like in the situation I just described, the child component isn't designed with all identifiers used in the parent component in mind - which is perfectly reasonable, that's what allows for so many things in programming to be modular (and adaptable and useful). As a result, sometimes you need a prop or variable to have one name in the parent component, and another in the child component, which requires the

<Child otherName={functionName}/>

approach.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!