mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-02-23 02:54:58 +01:00
26 lines
679 B
TypeScript
26 lines
679 B
TypeScript
import { readText, writeText } from '@tauri-apps/plugin-clipboard-manager';
|
|
import { useCallback, useEffect } from 'react';
|
|
import { useWindowFocus } from './useWindowFocus';
|
|
import { createGlobalState } from 'react-use';
|
|
|
|
const useClipboardTextState = createGlobalState<string>('');
|
|
|
|
export function useClipboardText() {
|
|
const [value, setValue] = useClipboardTextState();
|
|
const focused = useWindowFocus();
|
|
|
|
useEffect(() => {
|
|
readText().then(setValue);
|
|
}, [focused, setValue]);
|
|
|
|
const setText = useCallback(
|
|
(text: string) => {
|
|
writeText(text).catch(console.error);
|
|
setValue(text);
|
|
},
|
|
[setValue],
|
|
);
|
|
|
|
return [value, setText] as const;
|
|
}
|