Skip to content

useCssVar ​

utilities
test coverage
Last changed: 24 days ago

Hook that returns the value of a css variable

typescript
import { useCssVar } from '@siberiacancode/reactuse';

Usage ​

typescript
const { ref, value, set } = useCssVar('--color', 'red');
// or
const { value, set } = useCssVar(ref, '--color', 'red');

Demo ​

Api ​

Parameters

NameTypeDefaultNote
keystring-The CSS variable key
initialValuestring-The initial value of the CSS variable

Parameters

NameTypeDefaultNote
targetHookTarget-The target element
keystring-The CSS variable key
initialValuestring-The initial value of the CSS variable

Source ​

Source • Demo

Contributors ​

Avatardebabin

Released under the MIT License.