我只是最近尝试使用react hook。
如果我扩展Componet,我将这样声明我的状态:
constructor(props) {
super(props);
// dummy state
this.state = {
focus: false
name: 'test'
image: ''
avatarSource: '',imageBase: 'sfsafsfasf',imageLoader: null,}
如果我想发送所有状态值,我将使用...this.state
就像:
sendStateFunction(...this.state);
如果我使用react hook,我会这样声明我的状态:
const test = () => {
const [name,setName] = useState('');
const [image,setImage] = useState('');
const [sex,setSex] = useState(0);
const [id,setId] = useState('');
}
但是我不知道如何仅使用一行代码发送所有状态值:
sendStateFunction(); // What should I type the arguments ?