React Flashcards
What is React?
React is a JavaScript library to facilitate the creation of interactive, stateful and reusable UI components.
What is the virtual DOM?
It is an abstraction of the HTML DOM. It allows React to do its computations within the abstract DOM without the real DOM operations, often slow and browser-specific.
In most cases, what do you need to to transform HTML code into a static React component?
- Return the HTML code in render.
- Replace class attribute name to className (because class is a reserved word in JavaScript).
What is the directory node_modules/?
It contains all the dependencies that the package manager loads based on the dependencies list defined in the package.json file.
What is the directory public/?
- Public root of the site.
- Files in there are accessible to anyone on the web.
- Good place to keep static files and assets that are not being managed in the src/ directory.
What is the src/ directory?
The application code!
Where does the browser look for the initial instructions to render the React app?
public/index.html
Does the public/index.html file has to be blank? Why not?
No: you can add whatever static design frame and elements around the React element, and know that the app will appear inside that element when JavaScript executes.
What is src/index.js?
It is the file where React looks for initial instructions to build UI inside the root element defined in public/index.html.
What are the two different ways to import modules, assuming Webpack is used?
- Modules defined in package.json and installed can be imported by name ==> e.g. import {Module} from ‘module’;
- Modules that are not package.json can still be imported by specifying a path to the file where those modules are defined ==> e.g. import {Module} from ‘path/to/module’;
What are the arguments of the render() function within src/index.js?
- A React component to render: the ‘App’ component from src/app.js
- A DOM node to serve as the render container, that is, the root element.
Why can we use HTML and JSX expressions in a React app JavaScript file?
Because the JSX interpreter will compile the JSX tags and HTML tags into calls to React.createElement(). Incidently, the React module has to be imported even if not seemingly used.
What is the component < App/ >?
- It is the first component the React app will call in index.js.
- It serves as the container for rendering all the other components in the app.
What are all components expected to do?
All components are expected to define a function called render() that returns some DOM elements.
Why are curly brackets special inside JSX tags?
They indicate that the code inside the curly brackets is JavaScript. It can be used to print the evaluated value of a JavaScript expression in the generated markup.
What cannot be put inside curly brackets inside JSX tags?
Statements CANNOT be within these curly brackets, but any JavaScript expression can be.
How to run a React app in development?
$ npm start
What does $ npm test does?
It launches a test runner (i.e. Jest) watching changes to the app and trying to run related tests.
What does $ npm run build does?
It packages the app for a production deployment, at /build/static/js/.
How does React handles non-JavaScript assets?
Webpack loaders (which create-react-app is using behind the scenes to build the app) let you load them directly in Javascript through the module system if files are included in the ‘src’ directory.
What is a SPA (Single Page Application)?
A SPA website usually loads once, then rewrites sections of a page rather than loading entire new pages from a server.
What are React components?
- Conceptually, components are like JavaScript functions.
- They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.
- Components are stateful and reusable.
What are Web components?
- Reusable page elements that encapsulate pieces of functionality.
- Examples:
- Search input that offers live previews of search results.
- Button that shows a tooltip on hover.
- They are distinct and complementary to React components.
What is JSX?
- It is a templating language combining HTML and JavaScript into a single file.
- It is mostly a syntactic convenience for building up JavaScript objects that describe DOM elements.