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

347
Visualizações
Show and hide div in react js

How do I hide my page "section" when I click on a button. and show it another button is clicked Here's my code

import './App.css';
import Typed from 'react-typed';
import { useState, useEffect } from 'react';
function App() {
  return (
    <div className='text-white'>
      <div id='index' className='index max-w-[800px] mt-[-96px] w-full h-screen mx-auto text-center flex flex-col justify-center'>
        <div className='flex justify-center items-center'>
          <h1 className='md:text-7xl sm:text-6xl text-4xl font-bold md:py-6'>Roll</h1>
          <Typed 
          className="md:text-7xl sm:text-6xl text-4xl font-bold md:py-6 text-gray-400"
          strings={['simply', 'design']} 
          typeSpeed={70} 
          backSpeed={100} 
          loop/>
        </div>
        <p className='md:text-3xl sm:text-2xl text-xl font-bold py-4 '>best <a className='underline text-gray-300'>design</a> and <a className='underline text-gray-300'>simplistic.</a></p>
        <button className='bg-white text-black w-[200px] transition-[0.5s] rounded-lg font-bold my-6 mx-auto py-3 ring-2 ring-gray-300 hover:bg-slate-300  hover:shadow-xl hover:shadow-white hover:scale-110 '>Create</button>//clicking this button will show the div below which has the id of info and hide this current div
      </div>
      <div id='info' className='info max-w-[800px] mt-[-96px] w-full h-screen mx-auto text-center flex flex-col justify-center'>
        <h1>Hello</h1>
      </div>
      <div id='ino' className='info max-w-[800px] mt-[-96px] w-full h-screen mx-auto text-center flex flex-col justify-center'>
        <h1>Hello</h1>
      </div>
    </div>
  );
}

how do i make the onClick event work it out?

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

Just set a state let's call it for example hide and set default value false, and on the button click turn it to true.

And you can conditionally hide the button section and show the info section.

import "./App.css";
import Typed from "react-typed";
import { useState, useEffect } from "react";
function App() {
  const [hide, setHide] = useState(false);
  return (
    <div className="text-white">
      {!hide ? (
        <div
          id="index"
          className="index max-w-[800px] mt-[-96px] w-full h-screen mx-auto text-center flex flex-col justify-center"
        >
          <div className="flex justify-center items-center">
            <h1 className="md:text-7xl sm:text-6xl text-4xl font-bold md:py-6">
              Roll
            </h1>
            <Typed
              className="md:text-7xl sm:text-6xl text-4xl font-bold md:py-6 text-gray-400"
              strings={["simply", "design"]}
              typeSpeed={70}
              backSpeed={100}
              loop
            />
          </div>
          <p className="md:text-3xl sm:text-2xl text-xl font-bold py-4 ">
            best <a className="underline text-gray-300">design</a> and{" "}
            <a className="underline text-gray-300">simplistic.</a>
          </p>
          <button
            className="bg-white text-black w-[200px] transition-[0.5s] rounded-lg font-bold my-6 mx-auto py-3 ring-2 ring-gray-300 hover:bg-slate-300  hover:shadow-xl hover:shadow-white hover:scale-110"
            onClick={() => setHide(true)}
          >
            Create
          </button>
          //clicking this button will show the div below which has the id of
          info and hide this current div
        </div>
      ) : (
        <div
          id="info"
          className="info max-w-[800px] mt-[-96px] w-full h-screen mx-auto text-center flex flex-col justify-center"
        >
          <h1>Hello</h1>
        </div>
      )}
      <div
        id="ino"
        className="info max-w-[800px] mt-[-96px] w-full h-screen mx-auto text-center flex flex-col justify-center"
      >
        <h1>Hello</h1>
      </div>
    </div>
  );
}

about 4 years ago · Santiago Gelvez Relatório

0

You should use useState() react hook.

For example:

import './App.css';

function App() {
  
  const [visible, setVisible] = useState(true);

  return (
    <div className='text-white' style={{display: visible ? 'block' : 'none'}}>
      <div>
        <!--first part-->
        <div className='flex justify-center items-center'>
          <h1 className='md:text-7xl sm:text-6xl text-4xl font-bold md:py-6'>Web</h1>
          <!--stuff here-->
        </div>
        <p>stuff here</p>
        <button onClick={() => setVisible(!visible)}>Create</button>
        <!--when i click on the button it will hide the first part(section) and show the second part -->
      </div>
      <!--first part end -->
      <div>
        <!--second part -->
        <h1>Hello</h1>
      </div>
  </div>
);

You could check more details how to use useState() hook here https://reactjs.org/docs/hooks-state.html

about 4 years ago · Santiago Gelvez 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