Rename on Destructure
Use key: newName to import a property under a different variable name, avoiding naming conflicts.
Use key: newName to import a property under a different variable name, avoiding naming conflicts.
const { data: userData, error: fetchError } = await getUser(id);
// Property "data" is now "userData", "error" is "fetchError"
// Rename + default combined
const { timeout: requestTimeout = 5000, retries: maxRetries = 3 } = config;
// Useful when two sources have same key name
const { id: userId } = user;
const { id: postId } = post;
Renaming is syntax sugar — the original object is untouched.
More in JavaScript