[Composable] Vue3 Composable to improve performance #205
craigrileyuk
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Most of the documentation and functionality is based around the React way of doing things. That is, whenever something changes, the entire template function is re-run again and all functions are re-executed, including
tv()
and the tailwind-merge that backs it up.As a one-off, it's fine, but if you have dozens of components running lots of instances, it can add up.
Vue3 has a pretty granular reactivity system so functions are only re-run if a reactive dependency changes.
For the standard
tv
function, this is simple as:and then implement it using:
But if you're using slots, this approach won't work as the
tv
function now returns other functions that won't be reactive.I was messing around with this and came up with the following solution:
Which you can use like so:
where the first argument is your call to the main function and the second (optional) argument is any needed slot overrides.
Hope this helps someone out there.
Beta Was this translation helpful? Give feedback.
All reactions