Skip to content
Discussion options

You must be logged in to vote

The React way is actually to pass the behavior into Tabs as a callback:

// Tabs.js
function Tabs(props) {
  const handleTabChange = (event) => {
    // ...
    props.onTabChange();
  }
  // ...
}

// your-page.{md,js}
<Tabs onTabChange={() => console.log("Tabs changed")} />
// ...

If you absolutely need to emit events, do it in the old way with DOM:

function Tabs(props) {
  const ref = React.createRef();
  const handleTabChange = (event) => {
    // ...
    ref.current?.dispatchEvent(new Event('tabChange'));
  }
  return (
    <div ref={ref}>
       {/* the component */}
    </div>
  )
}

(Hope the latter works, correct me if it doesn't)

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@gouku
Comment options

Comment options

You must be logged in to vote
1 reply
@gouku
Comment options

Answer selected by gouku
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants