frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

16 - re-render - react

Open jsartisan opened this issue 1 year ago • 0 comments

App.jsx

import { useState } from 'react';

import { Button } from './components/button';
import { ModalDialog } from './components/basic-modal-dialog';
import { VerySlowComponent } from './components/very-slow-component';
import { BunchOfStuff, OtherStuffAlsoComplicated } from './components/mocks';

export default function App() {
  return (
    <>
      <ButtonWithDialog />
      <VerySlowComponent />
      <BunchOfStuff />
      <OtherStuffAlsoComplicated />
    </>
  );
}

function ButtonWithDialog() {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <>
      <Button onClick={() => setIsOpen(true)}>Open dialog</Button>
      {isOpen ? <ModalDialog onClose={() => setIsOpen(false)} /> : null}
    </>
  );
}

jsartisan avatar Sep 08 '24 06:09 jsartisan