What is the difference between these two state updating functions and what is the recommended approach? Both functions work fine in my application.
Option 1
const [profile, setProfile] = useState<{name: string, age: number}>({
name: 'John Doe',
age: 28,
});
setProfile((prevState) => {
return {
...prevState,
age: profile.age + 100,
}
});
Option 2
const [profile, setProfile] = useState<{name: string, age: number}>({
name: 'John Doe',
age: 28,
});
setProfile({
...profile,
age: profile.age + 100,
});