question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use composition hook with ref to the component?

See original GitHub issue

I get an error when I try to use a hook with a component

tippy() was passed a plain object which is not supported as an argument for virtual positioning. Use props.getReferenceClientRect instead.

And

DOMException: Failed to execute 'querySelectorAll' on 'Document': '[object Object]' is not a valid selector.

TheNavigation.vue

<template>
	<div>
		<BaseButton
			label="Open dropdown"
			ref="triggerElement"
		/>

		<div ref="contentElement">
			Content
		</div>
	</div>
</template>

<script lang="ts">
import { defineComponent, ref } from '@vue/composition-api';
import { useTippy } from 'vue-tippy/composition';

import { BaseButton } from '@/components';

export default defineComponent({
	components: {
		BaseButton
	},
	setup() {
		const triggerElement = ref(null);
		const contentElement = ref(null);
		
		const { tippy } = useTippy(triggerElement, {
			content: contentElement,

			placement: 'bottom',
			animation: 'shift-away',
			role: 'dropdown',
			arrow: false,
			trigger: 'click',
			appendTo: 'parent',
			interactive: true
		});
		
		return {
			tippy,
			triggerElement,
			contentElement
		};
	}
});
</script>

BaseButton.vue

<template>
	<button>
		<slot>
			{{ label }}
		</slot>
	</button>
</template>

<script lang="ts">
import { defineComponent } from '@vue/composition-api';

export default defineComponent({
	props: {
		label: {
			type: String,
			default: null
		}
	},
	setup() {
		return {};
	}
});
</script>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

Refs and the DOM - React
Refs are created using React.createRef() and attached to React elements via the ref attribute. Refs are commonly assigned to an instance property when...
Read more >
Advanced compositional React with useContext, useRef, and ...
Let's learn how to use React 16.8's hooks API to create a clean, compositional UI component. This article assumes you're familiar with hooks...
Read more >
How to use $refs in Vue 3 with Composition API and Script ...
This post is going to explain how to use Ref in Vue 3, while using the Composition API and the Script Setup. The...
Read more >
Vue 3 Composition API - "ref" and "reactive" - This Dot Labs
The Composition API provides two different ways to store data locally in the component - “ref” and “reactive”. These two methods serve a...
Read more >
How to get $refs using Composition API in Vue3?
In my code I use Template Refs: ref is a special attribute, that allows us to obtain a direct reference to a specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found