Last active
December 17, 2021 16:16
-
-
Save colinfwren/24e92763b5c3dfe04ad4ac5aa9f74ee4 to your computer and use it in GitHub Desktop.
Listening for Miro events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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