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

176
Visualizações
Where to get props and set props in a functional component in React Js?
props data coming from the parent component

const [state, setState] = useState({

reportTypesVal: { label: "", value: "" } || props?.reportTypesVal});

Why I'm unable to set data like this to reportTypesVal? If I try to set data in useEffect It doesn't set the value to reportTypesVal. How can I do this?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Your question is a bit unclear, but from the title:

Where to get props and set props in a functional component in React Js?

I assume you're asking how to pass props, here is an example on the new beta documentation: https://beta.reactjs.org/learn/passing-props-to-a-component

about 4 years ago · Juan Pablo Isaza Relatório

0

You should implement it in the child name function.

EX:

import ...
import ...

function showSomething( {MyProps1, MyProps2} )  // <---- here
{
   useEffect(() => {
        
        console.log(MyProps1);      

   }
...
}
about 4 years ago · Juan Pablo Isaza Relatório

0

This is how you pass props into a component:

<Component property={'randomText'} />

This is how you retrieve it in the component:

function Component (props) = {
  return (
    <p>{props.property}</p>
  )
}

You can change the property inside of the component by using states and passing the set function as a property:

const [randomText, setRandomText] = React.useState('randomText')
return(
    <Component property={randomText} propertySet={setRandomText} />
)

Inside the component you can do:

function Component (props) = {
      return (
        <button onClick={() => {props.setRandomText('randomText2')}}>{props.randomText}</button>
      )
    }

Then when you click the button it will change to 'randomText2'

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