我如何将形式的数据存储为reactj中localstorage的数组
我拥有的一些状态
const initialValues = {companyname:"", email:"", phone:"",website:""}
const [formValues, setFormValues] = useState(initialValues);
const [formErrors, setFormErrors] = useState({});
const [isSubmit, setIsSubmit] = useState(false);
试图将形式的数据(FormValues)存储在LocalStorage中,从提交中以将其存储在数组中,但不能在数组中进行
useEffect(()=>{
localStorage.setItem('formValues',JSON.stringify(formValues) );
},[formValues]);
``
[![**enter image description here**][1]][1]
[1]: https://i.sstatic.net/7yprY.png
some of the states i had
const initialValues = {companyname:"", email:"", phone:"",website:""}
const [formValues, setFormValues] = useState(initialValues);
const [formErrors, setFormErrors] = useState({});
const [isSubmit, setIsSubmit] = useState(false);
trying to store form data (formValues) in localStorage on from submit to store it in it as an array but cant do it in array
useEffect(()=>{
localStorage.setItem('formValues',JSON.stringify(formValues) );
},[formValues]);
``
[![**enter image description here**][1]][1]
[1]: https://i.sstatic.net/7yprY.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您代码的小例子
here is the small example of your code