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

179
Visualizações
How to render a component when a specific component will render?

This is the sample code:

<Route exact path='/user'>
    <UsersList />
</Route>
<Route path='/user/:name'>
    <Sidebar />
    <User />
</Route>
  • UsersList component is like a home/landing page.
  • UsersList and Sidebar both the components contains list of links. When we click any of the link, we will be redirected to that users page.
  • User component will render the information of that specific user.

Let say we are on /user/john and want go on /user/jack. But when I am doing this i.e. when I am clicking on the link to go from /user/john to /user/jack, React is re-rendering the Sidebar component.

But I want that Sidebar component should render only once and only when path='/user/:name'. So, how to do it?

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

0

To realize what you really want, you need to use layout.

If you introduce layout, it would be look like this.

<container>
    <appbar>
    </appbar>
    <content>
        <sidebar>
        </sidebar>
        <Route path='/user/:name'>
        </Route>
    </content>
</container>

For example take a look at this. (You need to search the demo based on the framework you are using)

about 4 years ago · Juan Pablo Isaza Relatório

0

If you can move the Sidebar component out the Route component, then use the React.Fragment shorthand tag as a parent component for all the JSX elements.

So you should use this

<>
  <Sidebar />
  <Route path='/user/:name'>
    <User />
  </Route>
</>
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