How do I change a property inside a useContext?
export const AuthContext = createContext();
const { obra, setObra } = useContext(AuthContext);
setObra(...obra, ...obra.nome_equipe_01 = e.target.value);
I Want to change the property 'nome_equipe_01' inside the 'obra' object
CodePudding user response:
You need to override the intended key, for example:
setObra(prevState => ({...prevState, nome_equipe_01: e.target.value }))
CodePudding user response:
setObra({...obra,nome_equipe_01: "value"})
or you can create a specific function that update specific prop on the context