我有一个包含一些状态的组件。之间有什么不同
示例 1:
function CompA() {
[a, setA] = useState(0);
[b, setB] = useState("Test");
return (<div>{{ a }} and {{ b }}</div>);
}
和示例 2:
function CompA() {
[state, setState] = useState({a: 0, b: "Test"});
return (<div>{{ state.a }} and {{ state.b }}</div>);
}
示例 2 更详细。但是我在网上看到的所有钩子示例都更喜欢示例 2 的风格。是否有任何性能损失或最佳实践偏爱一种或另一种?