You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the only way to have reactive props in a 'root' component is to use a functional component:
constprops=reactive({check: 1});constapp=createApp(()=>h(App,props));app.mount("#app");props.check+=1;// Will trigger watch
This is kinda annoying, but I can live with it.
Root Reactive Props + expose
However, an issue arises if you want to use exposed variables from your component: .mount() currently does not return an instance when instantiating functional components. Since that's how you get access to exposed variables, you can't access them in a conventional manner:
constprops=reactive({check: 1});constapp=createApp(()=>h(App,props));constinstance=app.mount("#app");props.check+=1;instance.func();// error: instance is null for functional components
There are some ways to circumvent this issue, but they're all kinda hackish:
// Approach 1: Use funcional component and access through 'app1._instance.subTree.component.exposed'constprops=reactive({check: 1})constapp=createApp(()=>h(App,props));app.mount("#app");props.check+=1;app._instance.subTree.component.exposed.func();// Approach 2: Use the more common creation method, and access props through 'app._instance.props'constapp=createApp(App,{check: 1});constinstance=app.mount("#app");app._instance.props.check+=1;instance.func();
Solution
IMO, there are 2 ways to solve this issue:
Make it so createApp accepts reactive objects as its second argument
Return instances from .mount() even when the component is a functional component
Ideally both would get implemented, but as long as either of them get solved this use case will get a lot better.
I'm not 100% sure if those would be considered bugs of feature requests, so I'm opening this discussion to gather some feedback.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Root Reactive Props
Consider a component like this:
Currently, the only way to have reactive props in a 'root' component is to use a functional component:
This is kinda annoying, but I can live with it.
Root Reactive Props +
expose
However, an issue arises if you want to use
expose
d variables from your component:.mount()
currently does not return an instance when instantiating functional components. Since that's how you get access toexpose
d variables, you can't access them in a conventional manner:There are some ways to circumvent this issue, but they're all kinda hackish:
Solution
IMO, there are 2 ways to solve this issue:
createApp
acceptsreactive
objects as its second argument.mount()
even when the component is a functional componentIdeally both would get implemented, but as long as either of them get solved this use case will get a lot better.
I'm not 100% sure if those would be considered bugs of feature requests, so I'm opening this discussion to gather some feedback.
Beta Was this translation helpful? Give feedback.
All reactions