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

220
Visualizações
Application state architecture: how to structure state with similar properties?

I have a state headerState that controls two UI elements: Mobile navbar and Auth dialog.

Mobile navbar and auth dialog both have properties isOpen, open and close

I need to come up with a flexible and extendible solution on how to structure the state.

I see several ways of solving this problem:

type NoArgsNoReturn = () => void;
// structure by category: navMenu and authDialog
type HeaderState = {
  navMenu: { isOpen: boolean; open: NoArgsNoReturn; close: NoArgsNoReturn },
  authDialog: { isOpen: boolean; open: NoArgsNoReturn; close: NoArgsNoReturn }
};

// structure by what they do
type HeaderState = {
  isOpen: { navMenu: boolean; authDialog: boolean },
  open: { navMenu: NoArgsNoReturn; authDialog: NoArgsNoReturn },
  close:{ navMenu: NoArgsNoReturn; authDialog: NoArgsNoReturn }
};

// separate states
type HeaderState = {
  isNavMenuOpen: boolean;
  isAuthDialogOpen: boolean;
  // if `open` is provided, isNavMenuOpen will be set to `open`, otherwise it will be toggled
  setNavMenuOpen: (open?: boolean) => void; 
  // same for `isAuthDialogOpen`
  setAuthDialogOpen: (open?: boolean) => void; 
}

But I can't figure out what would be the best way to structure it, there must be some best practices or practices developed from experience.

about 4 years ago · Juan Pablo Isaza
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