Leveraging vue-devtools in combination with the composition-api while implementing a render function (such as JSX)

Ever since I made the transition to utilizing the composition-api and incorporating a render function (primarily leveraging JSX with TypeScript for type safety within the template), I've encountered an issue where vue-devtools cannot inspect the computed properties. This limitation arises from these properties no longer being directly accessible by the component, despite props remaining accessible.

What strategies can I implement to ensure robust TypeScript support in my templates while also retaining the ability for vue-devtools to inspect computed properties?

For instance, consider this previous approach using .vue files implementing the composition-api which was vue-devtools-friendly but lacked TypeScript support in the template:

SomeComponent.vue

<template>
  <div>
    <ul>
      <li>{{ computedProperty }}</li>
    </ul>
  </div>
</template>

<script lang="ts">
  export default defineComponent({
    name: "SomeComponent",
    props: { 
      // ...
    },
    setup(props, ctx) {
      const computedProperty = computed(() => {
        // return ...some calc
      })
  
      return {
        computedProperty
      }
    }
  })
</script>

Then, contrast it with this example utilizing .tsx files providing proper TypeScript support in the template, albeit at the cost of vue-devtools' inability to directly inspect computedProperty:

SomeComponent.tsx

export default defineComponent({
    name: "SomeComponent",
    props: { 
      // ...
    },
    setup(props, ctx) {
      const computedProperty = computed(() => {
        // return ...some calc
      })
  
      return () => (
        <div>
          <ul>
            <li>{ computedProperty.value }</li>
          </ul>
        </div>
      )
    }
  })

How can we bridge the gap and achieve the benefits of both approaches seamlessly?

Answer №1

export default defineComponent({
    name: "NewComponent",
    props: { 
      // ...
    },
    setup(props, ctx) {
      const newComputedProperty = computed(() => {
        // return ...some calculation
      })

      return { newComputedProperty }
    },
    render() {
      return (
        <div>
          <ul>
            <li>{ this.newComputedProperty.value }</li>
          </ul>
        </div>
      )
    }
  })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can elements be connected in Vue using a delimiter?

When it comes to Python, there is a straightforward method to link elements together with a separator solely placed between the "inner" components: >>> print(" → ".join(['hello', 'world', 'bonjour'])) hello → wor ...

What are some ways to incorporate a Three.js script within a Vue project?

I encountered a challenge while trying to incorporate a three.js script written in vanilla JavaScript into a Vue project. The script utilizes the three function objLoader to import an object from a local file. While the script functions accurately in vanil ...

Unloading a dynamically-loaded child component in Vue.js from the keep-alive cache

I have a question that is similar to the one mentioned here: Vue.js - Destroy a cached component from keep alive I am working on creating a Tab System using Vue router, and my code looks something like this: //My Tab component <template> <tab& ...

Callback for dispatching a union type

I am currently in the process of developing a versatile function that will be used for creating callback actions. However, I am facing some uncertainty on how to handle union types in this particular scenario. The function is designed to take a type as inp ...

Unable to utilize the data-placed value in the template; only the props value is functional

I am utilizing the value from props and changing the class based on it. Below is the code that is currently working: <div class="modal" :class="{'is-active': aa}" > However, when I attempt to make a check based on the value of isActive fr ...

I need guidance on retrieving items from the useRouter() hook when utilizing Next.js with the App Router approach

This code snippet demonstrates how to use Pages Router in React import { useRouter } from "next/router"; import React from "react"; function ShowroomListings({}) { const router = useRouter(); const { listingId } = router.query as ...

What is the best way to extract all Enum Flags based on a Number in TypeScript?

Given: Enum: {1, 4, 16} Flags: 20 When: I provide the Flags value to a function Then: The output will be an array of flags corresponding to the given Enum: [4, 16] Note: I attempted to manually convert the Enum to an array and treat values as numb ...

Is it possible to create an Angular 2 service instance without relying on the constructor method?

I'm struggling to utilize my ApiService class, which handles API requests, in another class. Unfortunately, I am encountering a roadblock as the constructor for ApiService requires an HttpClient parameter. This means I can't simply create a new i ...

having difficulties with angular subscribing to an observable

I am currently working on a service that retrieves a post from a JSON file containing an array of posts. I already have a service in place that uses HttpClient to return the contents of a JSON file. The main objective is to display the full content of the ...

Utilize the composition API in Vue.js 3 to call a function and pass in a parameter

I'm having trouble calling a function from another component. When I click on a button in my parent component, formTelemarketing(), it should send data to my other component nAsignedCalls() and call the function getCalls(param) in that component. Thi ...

When we mention TypeScript and CDK, we are actually talking about the very foundation

As I was working on my current Stack constructor, I came across the Stack.formatArn() method. I started to wonder about the difference between using this.formatArn() and cdk.Stack.of(this).formatArn(). After all, shouldn't "this" refer to the stack it ...

Using Vue router to dynamically define the query key when calling router.push()

Hello, I am relatively new to using Vue and have been working on a project that involves making GET requests based on the current URL. In one of my functions, I am trying to dynamically set the value of filterType in the query key within the router.push() ...

Issues arise in Typescript single-page applications due to the use of application insights

Currently, I am developing a single-page HTML application using TypeScript in VSCode. Initially, the app was running smoothly without any errors or warnings. However, I decided to incorporate Azure Application Insight into the project. To integrate it, I ...

Conflicting Angular controller names within different modules

I'm facing an issue where two modules (A and B) with controllers of the same name are conflicting when imported into module C. Is there a recommended solution to prevent this conflict, such as using a naming convention like "module.controller" for ea ...

Utilizing a library that solely enhances the functionality of the Array object

I have a library with type definitions structured like this: declare global { interface Array<T> { addRange<T>(elements: T[]): void; aggregate<U>(accumulator: (accum: U, value?: T, index?: number, list?: T[]) => an ...

Create a collection of objects within Vue

I have been using Objects in Arrays successfully to read data, but I am having trouble initializing them. I require more variables within articleList than just the number, so a normal array won't suffice. Below is what has been working: data(){ ...

The value returned by a mocked Jest function is ignored, while the implemented function is not invoked

Having an issue with mocking the getToken function within my fetchData method in handler.ts while working with ts-jest. I specifically want to mock the response from getToken to avoid making the axios request when testing the fetchData method. However, des ...

"Implementing a retry feature for Angular http requests triggered by a button

Imagine having a situation where a component has a method that triggers an http request defined in a service. The observable is subscribed to within the component: Component: fetchData() { this.apiService.fetchDataFromServer().subscribe( respo ...

Encountering unanticipated breakpoints in compiled .Next files while using Visual Studio Code

As a newcomer to NextJS, I have encountered an issue that is disrupting my workflow. I followed the instructions in https://nextjs.org/docs/advanced-features/debugging#using-the-debugger-in-visual-studio-code to set up my launch.json file. Although I am ...

Using create-react-app with TypeScript for server-side rendering

My current project is built with create-react-app using typescript (tsx files). I'm now interested in implementing SSR for the project, but I'm not exactly sure where to begin. In the past, I've successfully implemented SSR with typescript ...