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

209
Views
How to pass parameter to function inside react component..?

I need to pass a parameter to the common function when my dom is loaded. I can't use useEfect in my case. So I create a function for that. I need to check some parameters' true and if it is true I return true or I return false.

export function validateUser(data) {
  if (data==='order/view'){
    return true
  }
    return false
  
}
export default validateUser();




return (
    <div hidden={()=>{validateUser('order/view')}}> Som Data </div>
)

If div returns 'order/view' I need to show my div and if it's not, I need to hide my div in my react site. But My method can't return the parameters that I send it to. If anyone can help me with that question, It really helps.

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

0

If I'm understanding your question correctly, you are wanting to call validateUser to conditionally set the hidden prop being passed to the div. Instead of passing an anonymous callback just directly invoke validateUser and pass the return value as the hidden prop value.

export function validateUser(data) {
  return data === 'order/view';
}
export default validateUser();

...

return (
  <div hidden={validateUser('order/view')}>Some Data</div>
)

or if you really are conditionally rendering some content

return validateUser('order/view') ? (
  <div>Some Data</div>
) : null
about 4 years ago · Juan Pablo Isaza Report

0

You can do something like this

const validateUser = data => data === 'order/view'



export const ChildComponent = ({data}) => {



return (
    <div hidden={()=>{validateUser(data)}}> Som Data </div>
)

}

const ParentComponent = (props) => {

  return <>
    <ChildComponent data={props.data} />
  </>
}

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!