Skip to content

props to attach functions to events #412

Answered by diegohaz
vitordino asked this question in Questions
Discussion options

You must be logged in to vote

I usually suggest this approach:

const state = useDialogState();

React.useEffect(() => {
  if (state.visible) {
    // onShow
  } else {
    // onHide
  }
}, [state.visible]);

Related: https://spectrum.chat/reakit/general/how-to-react-on-dialog-events~710e0748-288e-4196-a030-2243eede50ca

You can also create something like useUpdateEffect to handle only updates.

But, yes, wapping it within an enhanced hook is also a good option.

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by diegohaz
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #412 on September 08, 2020 19:53.