I am developing a web app using React and am using context API to store some information across multiple components of different hierarchy. I am storing an object that looks like below on App.js:
/*
import Userinfo from './context/Userinfo'
*/
function App() {
const [userinfo, setuserinfo] = useState({id: some_id, username: some_username, profile_picture: some_profile_picture})
/*
*/
}
and then use the context on a deeper component like below:
import Userinfo from '../context/Userinfo';
function Profile() {
const {userinfo, setuserinfo)=useContext(Userinfo);
const infoupdate = () => { //Function to update the userinfo stored by context API
setuserinfo({id: new_id, username: new_username, profile_picture: new_profile_picture})
}
/////////
The question is, how do I update only one pair of the stored object? For example, let's say I want to update only 'id' part while keeping the other fields same. What would be the syntax to do this?
Thanks a lot in advance!