Performance: Composable naming conventions (use prefix)
This affects code maintainability and load performance by enabling better tree-shaking and reducing unnecessary imports.
export function useData() { /* ... */ } export function useUser() { /* ... */ } export function useFetchData() { /* ... */ }
export function useData() { /* ... */ } export function useUser() { /* ... */ } export function fetchData() { /* ... */ }
| Pattern | Bundle Size Impact | Tree-shaking Effectiveness | Load Time | Verdict |
|---|---|---|---|---|
| No prefix or inconsistent naming | Higher | Poor | Slower | [X] Bad |
| Consistent 'use' prefix for composables | Lower | Good | Faster | [OK] Good |
use?use to clearly identify them as composables.use to follow Vue naming conventions.useFetchUserData clearly shows it is a composable fetching user data.export function useCounter() {
const count = ref(0);
function increment() { count.value++ }
return { count, increment };
}console.log(counter.count.value) after calling counter.increment() twice?count ref starts at 0.increment() increases count.value by 1, so after two calls, count.value is 2.export function fetchData() {
// composable logic
}use to be recognized as such.fetchData lacks the use prefix, so it breaks the convention.useAuthLogin, useAuthLogout, and useAuthStatus. Why is using the useAuth prefix a good practice?Pass the test and this pattern moves unknown