【发布时间】:2022-01-23 11:16:36
【问题描述】:
我有一个代码需要在 useState 中传递一个 const 有人可以帮忙吗??
以下代码在类构造函数中,我想将其转换为功能组件
类组件:
constructor(props){
super(props);
const {id, name, email} = props.location.state.contact;
this.state={
id,
name,
email
}
如何在功能组件中做到这一点?
【问题讨论】:
-
1.我建议使用功能组件。作为初学者,您将拥有更少的开销。你能提供你完整的类组件代码吗?
-
从 'react' 导入 {useState} 然后 const [name,setName] = useState("")
标签: reactjs use-state react-functional-component