Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Last active December 17, 2021 16:16
Show Gist options
  • Save colinfwren/24e92763b5c3dfe04ad4ac5aa9f74ee4 to your computer and use it in GitHub Desktop.
Save colinfwren/24e92763b5c3dfe04ad4ac5aa9f74ee4 to your computer and use it in GitHub Desktop.
Listening for Miro events
import React, { useEffect, useState } from 'react'
function App() {
const [selection, setSelection] = useState([])
const [isLoading, setIsLoading] = useState(true)
async function setInitialSelection() {
const selection = await miro.board.selection.get()
setSelection(selection)
}
function handleSelection({ data }) {
setSelection(data)
}
useEffect(() => {
miro.onReady(async () => {
miro.addListener('SELECTION_UPDATED', handleSelection)
await setInitialSelection()
setIsLoading(false)
})
return function cleanUp() {
miro.removeListener('SELECTION_UPDATED', handleSelection)
}
})
return {
// rest of app
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment