I'm looking at a piece of code that I don't understand:
const { data: user } = await axios.get(`/api/user/${id}`);
What does the { data: user }
part do? I've never seen an object get destructured and assigned to another variable. More confusingly, I'm testing it out live, and there doesn't seem to be a difference between { data: user } = ...
and { user } = ...
.
What's going on? There's a prop const [user, setUser] = useState(null);
earlier in the file, does that have anything to do with it?