我想在函数组件中使用uuid来设置具有动态键的动态状态。
下面是React中基于类的组件的示例。
class App extends Component {
state = {
[uuid()]: []
};
如何使用函数式组件实现此功能?
const App = props=>{
const [list, setList] = useState([uuid()]);
我尝试使用上述方法,它给了我输出:
["4b4c8872-0c35-49a6-a98b-ef7abcb2cef8"]
但期望的是["4b4c8872-0c35-49a6-a98b-ef7abcb2cef8": []]
提前致谢!