Import Destructuring
ES module named imports use the same brace syntax as object destructuring, letting you cherry-pick exports.
ES module named imports use the same brace syntax as object destructuring, letting you cherry-pick exports.
import { useState, useEffect, useCallback } from "react";
import { format, parseISO, addDays } from "date-fns";
// Rename import
import { get as httpGet, post as httpPost } from "./api.js";
// CommonJS equivalent
const { readFileSync, writeFileSync } = require("fs");
Named imports enable tree-shaking — bundlers drop unused exports from the final bundle.
More in JavaScript