Skip to content

getSelectedElements typescript issue? #1229

Answered by bcakmakoglu
AmosSzust asked this question in Q&A
Discussion options

You must be logged in to vote

General rule of thumb: Composable are not meant to be used in callbacks / functions.
There are exceptions (since composables are ultimately just functions) but useVueFlow is not one of them.
It's similar to React Hooks (but more flexible).

Call the composable in the setup body of your component (you can use any example on the vueflow docs as a reference to see how it's correctly used).

<script setup lang="ts">
const { getSelectedNodes, getSelectedEdges } = useVueFlow()

function deleteSelectedElements() {
	if (getSelectedNodes.value.length) { /* ... */ }
	// ...
}

Or if you want to use defineComponent:

export default defineComponent({
	setup() {
		const { getSelectedNodes, getSelectedEdges }

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@bcakmakoglu
Comment options

@AmosSzust
Comment options

@AmosSzust
Comment options

@bcakmakoglu
Comment options

Answer selected by AmosSzust
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