1

I am fairly new to ES6.

I am trying to call a function with two arguments:

export XYZ withFetching(noticeAPI)(promoIter)

and

export withFetching(noticeAPI)(promoIter)

It works when I do it as:

export default withFetching(noticeAPI)(promoIter)

The function looks like this:

const withFetching = (url) => (Comp) =>

Why does it work with the default keyword but not with any type of names?

Sorry if this is a dumb question about ES6, but I've tried every variation of the export syntax that I found on here with no luck.

https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export

2 Answers 2

1
export default withFetching(noticeAPI)(promoIter);

is short for

const _invisibleVariable_ = withFetching(noticeAPI)(promoIter);
export { _invisibleVariable_ as default };

So given your example

export XYZ withFetching(noticeAPI)(promoIter)

assuming you want XYZ to be the name, you can do

const XYZ = withFetching(noticeAPI)(promoIter);
export { XYZ };

or

export const XYZ = withFetching(noticeAPI)(promoIter);
Sign up to request clarification or add additional context in comments.

Comments

0

Hi did you try like this ?

export const XYZ = withFetching(noticeAPI)(promoIter);

And then importing it like this

import { XYZ } form 'somepath';

3 Comments

I did try export const XYZ = withFetching(noticeAPI)(promoIter); at one point, and I get the error: Line 42: Parsing error: Unexpected token on the export withFetching etc line
How about export const XYZ = (noticeAPI, promoIter) => withFetching(noticeAPI)(promoIter)
No error gets thrown with that, but when I try to use <XYZ /> after import in another component, console gives the error: Warning: Functions are not valid as a React child.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.