Where did apiClient come from when it is not even declared?

Hi everyone!

I am following the React 18 for beginners class, and I am at the part of Extracting a Reusable API Client.

I was just wondering how come we can do an 'import apiClient from “…/services/api-client” ’ when the apiClient is not even stated anywhere?


When you declare a default export like this:

// foo.ts
const foo = () => console.log("foo")
export default foo;

…you can import it using any aliased name you like, e.g.:

import bar from "./foo";

bar(); // logs "foo" to the console

In that video, Mosh is default exporting a value returned by axios.create:

That return value is what you’re aliasing to apiClient with your import statement.

1 Like

Thanks a lot for the info. I was about to ask this question. Yeah Mosh made it so easy for us. Keep going Mosh