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.

[Feature] useReactives

See original GitHub issue

I have an idea to make a helper function similiar to toRefs named toReactives which gets a ref object and decomposes it into a normal object which every key is a reactive instead of a ref.

I wanted to make this mainly for decomposing props because right now we only have toRefs to do this and this forces us to have a .value every time we want to reference props in code.

My idea was that since reactive() deeply unwraps refs, such implementations would work.

function toReactives(refObject) {

  const result = {};

  for (const key of Object.keys(refObject)) {
    result[key] = reactive(toRef(refObject, key));
  }

  return result;

};
function toReactives(refObject) {

  const result = {};

  for (const key of Object.keys(refObject)) {
    result[key] = reactive(computed(() => refObject[key]));
  }

  return result;

};
function toReactives(refObject) {

  const result = {};
  const refs = toRefs(refObject);

  for (const key of Object.keys(refs)) {
    result[key] = reactive(refs[key]);
  }

  return result;

};

but neither works, refs are not unwrapped in any of these. i am ok to submit a PR if i be able to fix this.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
antfucommented, Aug 16, 2021
  1. No, it’s a limitation of reactive / JS itself
  2. No, proxy only work on object. You will get a runtime error if you try that.
  3. Take a look at vue-global-api’s dist, you will find how to define your custom global apis. vue-global-api will only include vue’s composition-api itself for now
1reaction
antfucommented, Aug 15, 2021

close by #671

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reactive variables - Apollo GraphQL Docs
A query "depends on" a reactive variable if any of the query's requested fields defines a read function that reads the variable's value....
Read more >
How to use reactives in loops. What works, what doesn't and ...
How to use reactives in loops. What works, what doesn't and why. ... server <- function(input, output, session) {. rv <- reactiveValues(one =...
Read more >
Quick Start - ahooks 3.0
useRequest organizes code through a plug-in pattern, the core code is extremely simple, and can be easily extended for more advanced features.
Read more >
useReactive - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
Getting Started with React | Simple and Fun Reactivity
It also specifies a cleanup function that will run when the component that uses the resource is unmounted. Next, we'll use the useResource...
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