I am new to typescript and only have been working with react js files. Now i need to change some typescript files to js files.
Can someone explain or help me out with one of them so i can better understand how this can be achieved.
So this is a pretty simple one i think for example, what do i need to change in order to make it useable with an .js extension
The only thing marked as an error is: "as const" in the return function. But i dont know how to write this in plain js since i am also kinda new to javascript..
function usePip(ref: RefObject<HTMLElement>) {
const [styles, set] = useSpring(() => ({
x: 10,
y: 10
}));
const bind = useDrag(
({ down, last, movement: [x, y], metaKey, ...rest }) => {
let defaultX = 10;
let defaultY = 10;
if (last && ref.current) {
const rect = ref.current.getBoundingClientRect();
if (rect.x + rect.width / 2 > window.innerWidth / 4) {
defaultX = window.innerWidth / 2 - rect.width / 2 ;
}
if (rect.x + rect.width / 2 > window.innerWidth / 1.5) {
defaultX = window.innerWidth - 10 - rect.width;
}
if (rect.y + rect.height / 2 > window.innerHeight / 4) {
defaultY = window.innerHeight / 2 - rect.height / 2;
}
if (rect.y + rect.height / 2 > window.innerHeight / 1.5) {
defaultY = window.innerHeight - 10 - rect.height;
}
}
set({
x: down || metaKey ? x : defaultX,
y: down || metaKey ? y : defaultY,
immediate: down
});
},
{ initial: () => [styles.x.get(), styles.y.get()] }
);
return [bind, { ...styles, position: "fixed", left: 0, top: 0, zIndex: 99999 }] as const;
}