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

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

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 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