↼ All Hooks

useHover

useHover hooki, muayyan HTML elementiga sichqoncha bilan bosish holatini aniqlashga yordam beruvchi maxsus React hookidir.


useHover Hook

useHover hooki, muayyan HTML elementiga sichqoncha bilan bosish holatini aniqlashga yordam beruvchi maxsus React hookidir. Bu hover holatini kuzatish uchun oson interfeys taqdim etadi, bu esa interaktiv UI elementlarini qo'shish uchun juda qulaydir.

O'rnatish

npm install @udemere/usehooks

Foydalanish

import { useHover } from '@udemere/usehooks'
 
const HoverComponent: React.FC = () => {
	const [hoverRef, isHovered] = useHover<HTMLDivElement>()
 
	return (
		<div>
			<div
				ref={hoverRef}
				style={{
					width: '200px',
					height: '200px',
					backgroundColor: isHovered ? 'lightblue' : 'lightgray',
					transition: 'background-color 0.3s',
				}}
			>
				{isHovered ? 'Hover qilingan!' : 'Meni hover qiling!'}
			</div>
		</div>
	)
}

API

useHover

useHover<T extends HTMLElement>(): [React.RefObject<T>, boolean]

Parametrlar:

Natijalar:

Misol

import React from 'react'
import { useHover } from '@udemere/usehooks'
 
const ButtonWithHover: React.FC = () => {
	const [hoverRef, isHovered] = useHover<HTMLButtonElement>()
 
	return (
		<button ref={hoverRef} style={{ color: isHovered ? 'blue' : 'black' }}>
			{isHovered ? 'Hover qilingan!' : 'Meni hover qiling!'}
		</button>
	)
}
 
export default ButtonWithHover

Xususiyatlar: