Andrii Radkevych
Andrii Radkevych

Reputation: 3442

Export without destructuring

import { utils } from 'shared'

const {
  pick,
  get,
  isEmpty,
  sortBy,
  orderObjectsArray,
  isString
} = utils.lodashAlternative

export { pick, get, isEmpty, sortBy, orderObjectsArray, isString }

Above you can see exports , imagine I don't want to desctructure all of those functions , how can I do it ? I've tried to make export utils.lodashAlternative , but it will not work , also :

const {...data} = utils.lodashAlternative

export {...data}

Also will not work, it there any way to export it without discructuring ?

Upvotes: 1

Views: 134

Answers (1)

OtaconKiko
OtaconKiko

Reputation: 351

A simple way to export everything under utils.lodashAlternative is creating an alias and exporting that one instead. There's no need to create an object and spread lodashAlternative inside.

You can't declare and export afterwards (unless you use as)!

Way 1: using default

import { utils } from 'shared'

const lodashAlternative = utils.lodashAlternative;

export default lodashAlternative;

Way 2: exporting directly

import { utils } from 'shared'

export const lodashAlternative = utils.lodashAlternative;

Way 3: export each one separately, to be able to import them separately

import {utils} from "shared";

const { foo, bar } = utils.lodashAlternative;

export { foo, bar };

import then:

// WITH WAY 1
import lodashAlternative from "lodash-alternative";

// WITH WAY 2
import {lodashAlternative} from "lodash-alternative";

// WITH WAY 3
import {foo, bar} from "lodash-alternative";

Blitz here

Upvotes: 3

Related Questions