I'm new to react, and I have few question about some react expressions.
I was watching the video to learn how to drag and drop components. The code below works, but I got confused by these things.
- Why const variable bindLogoPos became a function inside div? (line 8, line 18)
- What does the three dot means in this code? (I've learned that three dots usually mean the rest of array or object. But I think bindLogoPos is not quite related to an array or object)
- What does it mean to use {...bindLogoPos()} like this way? Does it means to call function infinitely? Is this expression possible only in react?
import logo from './logo.svg';
import './App.css';
import {useState} from 'react';
import {useDrag} from 'react-use-gesture';
function App() {
const [logoPos, setLogoPos] = useState({x:0, y:0});
const bindLogoPos = useDrag((params)=>{
setLogoPos({
x: params.offset[0],
y: params.offset[1]
});
});
return (
<div className="App">
<header className="App-header">
<div {...bindLogoPos()} style={{
position:'relative',
top: logoPos.y,
left: logoPos.x,
}}>
<img src={logo} className="App-logo" alt="logo" />
</div>
////////more...