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

219
Visualizações
Is it possible to update props or declare props as var to render sub-component in child component? in NextJS

I build parent and child component name RightFrame, I want to display different component. so I using state to update child component and pass it as props. but I want the child component self can update the state (now props) too. but I know that the rule have to declare props as const so It can't update.

the parent component look like:

const [page, setpage] = useState();

return(
<button onClick={() => setpage("main")} 
...
<RightFrame page={page}/>
);

and RightFrame that have 3 sub-component and I want that to update page by them self to change page (since EditClass and CreateClass is the component that have action that can be cancel, so after cancel by button and go back to render Class by <button onClick={page = "main"})

export default function RightFrame(props) {
  const { page } = props;

  return (
  <>
    {page == "main" && <Class/>}
    {page == "edit" && <EditClass/>}
    {page == "new" && <CreateClass/>}
  </>
)

and that's the problem that I want to solve, so I don't know that it is possible to declare props as var on not.

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

0

You can pass the setPage as props so you can use the function to update it. Example

You can now use setPage in component child
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