Quiero establecer el valor de los errors en
{ email: { primary:"abc@gmail.com" } }Después de compilar, devuelve un error:
Cannot set properties of undefined (setting 'primary')Aplicación.js
import "./styles.css"; import { useState, useEffect } from "react"; export default function App() { const [errors, setErrors] = useState({}); useEffect(() => { const newErrors = errors; newErrors.email.primary = "abc@gmail.com"; }, []); return ( <div className="App"> <h1>Hello CodeSandbox</h1> <h2>Start editing to see some magic happen!</h2> </div> ); } Códigosycaja:
https://codesandbox.io/s/immutable-http-w0mue?file=/src/App.js
Porque newErrors.email no está undefined . Solo actualiza así:
newErrors.email = { primary: "abc@gmail.com" };