title: React Accordion component, calling hook after handler from within collapse
body: <p>I have a React Bootstrap accordion component. Within each of the cards of the accordion there is a task to complete and then a 'Save' button. This button writes the completed task to a database.</p>
  <p>I also want the save button to collapse the current card and expand the next card. I can achieve this by creating a customer Button component that calls useAccordionToggle(eventKey) onClick (before calling children):</p>
  <pre><code>function AccordianButton({ children, eventKey }) {
      return (
        &lt;Button
          onClick={useAccordionToggle(eventKey)}
        &gt;
          {children}
        &lt;/Button&gt;
      );
    }
  </code></pre>
  <p>So far so good!</p>
  <p>The problem is that I only want to collapse the accordion card <strong>once I am sure the database write has been successful</strong>.</p>
  <p>I can't figure out a way to do this. If I try to call useAccordionToggle in the handler function I get a hook error because I'm outside the component. Is there a way to do this?</p>