Skip to content

Latest commit

 

History

History
43 lines (40 loc) · 736 Bytes

File metadata and controls

43 lines (40 loc) · 736 Bytes

Hooks

useState

Initialize state with function

const [state, setState] = useState(()=>{
	//...rest
});

Generic

const Component = <T,>(props: Props<T>)=>{
	// ...component codes
}

Check text overflow state

const OverflowText = ()=>{
	const divRef = useRef(null);

	const isEllpisisActive = ()=>{
		if(!divRef.current) return false;

		return (
			divRef.currrent.offsetHeight < divRef.current.scrollHeight ||
			divRef.current.offsetWidth < divRef.current.scrollWidth
		);
	}

	return (
		<div
			ref={divRef}
			style={{
				overflow: 'hidden',
				textOverflow: 'ellipsis',
				whiteSpace: 'nowrap'
			}}
		>
			Super long long long long long long long long long long title
		</div>
	)
}