title: Toggle visibility of two components from buttons inside of them in React
body: <p>I have this structure</p>
  <p>component 1</p>
  <pre><code>import React, { useState } from 'react'
  
  export default function Component1() {
      return (
          &lt;div&gt;
              &lt;button onClick={handleChange}&gt;&lt;/button&gt;
          &lt;/div&gt;
      )
  }
  
  </code></pre>
  <p>component 2</p>
  <pre><code>import React, { useState } from 'react'
  
  export default function Component2() {
      return (
          &lt;div&gt;
              &lt;button onClick={handleChange}&gt;&lt;/button&gt;
          &lt;/div&gt;
      )
  }
  
  </code></pre>
  <p>and the parent</p>
  <pre><code>import React from 'react'
  
  export default function Parent() {
      return (
          &lt;div&gt;
              &lt;Component1 /&gt;
              &lt;Component2 /&gt;
          &lt;/div&gt;
      )
  }
  
  </code></pre>
  <p><strong>The question is, how can I toggle visibility between the two, without having a button in the parent. Just the buttons inside each component.</strong>  - The Component1 should be visible by default and when you press the button in Component1 it will hide it and show Component2 and vice-versa.</p>
  <p>I've tried using useState hook on the Component1 button, but I'm not sure how to export the state and add it to the parent component.</p>
  <pre><code>    const [showMini, setShowMini] = useState(false);
  
      const handleChange = () =&gt; {
        setShowMini(true);
      }
  </code></pre>
  <p>Is this possible? or it's possible just with a button in the parent that control the two?
  Thanks</p>