Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda