btholt / complete-intro-to-react-v4

The Complete Intro to React, as given for Frontend Masters
https://frontendmasters.com/learn/react/
1.14k stars 248 forks source link

import pf from petfinder-client #21

Closed winniethefoo closed 5 years ago

winniethefoo commented 5 years ago

Can you explain where the method pf is defined as I believe I don't really understand import?

1Marc commented 5 years ago

pf comes from the Pet Finder API module which is installed when you add the package to your package.json and run npm install.

winniethefoo commented 5 years ago

Can pf be any name or is it specific? I don't see pf defined in the Pet Finder API module. How do I know what to import when using someone elses API if its not documented?

1Marc commented 5 years ago

Yes you can name it anything you want. The documentation is the Typescript definitions https://github.com/btholt/petfinder-client/blob/master/index.d.ts

winniethefoo commented 5 years ago

So import { foo, bar, baz } from "bam"; means that bam is destructed where the modules are specifically imported. This would allow me to call foo, bar and baz.

However if I say import foo from "bam"; i am importing all modules from bam and assigning it to a new const which is an object called foo even if a foo module exists in bam. Which would then mean I would call foo.foo, foo.bar or foo.baz.

Is this understanding correct?

Is it possible a pull request could be made to update this in the documentation because I feel @btholt tutorials are very extremely beginner friendly to people of all levels of JavaScript but I was lost here on this specifically until you provided clarifications.

Thanks again @1Marc and @btholt

(Nevermind, just realised this is the code git and not the tutorial itself)

1Marc commented 5 years ago

Good tip. Time permitting I can add info about module imports. @winniethefoo