Skip to content

drag differents color regions in react #3805

Answered by katspaugh
anbotz asked this question in Q&A
Discussion options

You must be logged in to vote

The only possible problem I could spot with your code is this:

  useEffect(() => {
    if (regionsPluginRef.current) {
      regionsPluginRef.current.enableDragSelection({
        color: regionColor,
      })
    }
  }, [regionColor])

This will enable drag selection multiple times which is not something wavesurfer expects. It can lead to the drag gesture firing multiple times, i.e. creating multiple regions at once. You can fix it by adding a return:

  useEffect(() => {
    if (regionsPluginRef.current) {
      const disableDragSelection = regionsPluginRef.current.enableDragSelection({
        color: regionColor,
      })
      return disableDragSelection
    }
  }, [regionColor])

Replies: 1 comment 1 reply

Comment options

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

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