Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda