Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@kalxjs/composition

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kalxjs/composition

Composition API utilities for KalxJs framework

latest
Source
npmnpm
Version
1.2.16
Version published
Weekly downloads
1
-92.86%
Maintainers
1
Weekly downloads
 
Created
Source

@kalxjs/composition

Composition API utilities for KalxJs framework.

Installation

npm install @kalxjs/composition

Usage

import { useWindowSize, useLocalStorage, useMouse, useForm, useDebounce, useAsync } from '@kalxjs/composition';

// Window size hook
const { width, height, breakpoints } = useWindowSize();
console.log(width.value, height.value);
console.log(breakpoints.isMobile.value);

// Local storage hook
const { value, setValue, removeItem } = useLocalStorage('user-preferences', { theme: 'light' });
setValue({ theme: 'dark' });

// Mouse position hook
const { x, y } = useMouse();
console.log(x.value, y.value);

// Form handling hook
const { values, errors, touched, isSubmitting, isValid, setValue, reset, handleSubmit } = useForm(
  { name: '', email: '' },
  (values) => {
    const errors = {};
    if (!values.name) errors.name = 'Name is required';
    if (!values.email) errors.email = 'Email is required';
    return errors;
  },
  async (values) => {
    await api.post('/users', values);
  }
);

// Debounce hook
const searchTerm = ref('');
const debouncedSearchTerm = useDebounce(searchTerm, 500);

// Async hook
const { isLoading, error, data, execute } = useAsync(async (id) => {
  const response = await fetch(`https://api.example.com/users/${id}`);
  return response.json();
});

// Execute the async function
execute(1);

Available Hooks

useWindowSize

Track window dimensions with reactive references.

useLocalStorage

Persist state in localStorage with automatic serialization/deserialization.

useMouse

Track mouse position with reactive references.

useForm

Manage form state, validation, and submission.

useDebounce

Create a debounced version of a reactive value.

useAsync

Handle async operations with loading, error, and data states.

License

MIT

FAQs

Package last updated on 17 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts