Aspnet Core 3 React Book Flashcards
How does jsx is converted into regular JavaScript?
JSX is transformed into regular JavaScript by Webpack using a tool calledBabel. This is one of many tasks that CRA configured for us when our app was scaffolded.
What is minification?
Minificationis the process of removing unnecessary characters in files without affecting how it is processed by the browser. This includes code comments and formatting, unused code, using shorter variable and function names, and so on.
What is webpack?
Webpack is atool that transforms, bundles, and packages up files for use in a browser. Webpack also has a development server.
Note: The CRA tool has configured Webpack for us so that all the transformationand the bundling configuration are already set up for us.
How does react is served via aspnet? Is there any modification before actually serving it?
It is important to understand that the ASP.NET Core app runs on the server, with the React app running on the client in the browser. The ASP.NET Core app simply serves the files in theClientApp/Buildfolder without anyinterpretationor manipulation.
What is an import statement?
importstatement is used to import items that are exported by another JavaScript module. The module is specified by its file location, with thejsextension omitted.
What is the difference between importing a regular JavaScript and importing an item from a npm module?
Theimportstatements that import items fromnpmpackages don’t need the path to be specified because CRA has configured aresolverin Webpack to automatically look in thenode_modulesfolder during the bundling process.
CRA = Create react app
What does export default means? What does it have to do with the import with curly braces?
Theexportkeyword is used to export an item from a JavaScript module. Thedefaultkeyword defines the export as the default export, which means it can be imported without curly braces. So, a default export can be imported asimport App from ‘./App’rather thanimport {App} from ‘./App’.
What is the constructor in JavaScript? When to use it?
Theconstructorin a JavaScript class is a special method that automatically gets invoked when a class instance is created. So, it’s a great place to initialize class-level variables.
When to use componentDidMount method? When this method is invoked? What is its Function Component equivalent?
This method gets invoked by React when the component isinserted into the tree and is the perfect place to load data. Its Function Component equivalent is useEffect
What is an await on js? What kind of methods we can await?
Anawaitkeyword is used to wait for an asynchronous function to complete. A function must be declared as asynchronous in order to use theawaitkeyword within. This is done by placing anasynckeyword in front of the function name. This is very much likeasyncandawaitin .NET.
What does polyfill do?
Apolyfillis a piece of code that implements a feature we expect the browser to providenatively. Polyfills allow us to develop against featuresthat aren’t supported in all browsers yet.
How does de map function work?
Themapmethod is a native JavaScript method that is available in an array. It takes in a function parameter that is called for each array element. The return values of the function calls then make up a new array. Themapmethod is commonly used in JSX when iteration is needed.
What is the key attribute? When to use? Is it JavaScript default? What happens when it is not used?
Thekeyattribute helps React detect when an element changes, or is added or removed. So, it’s not a standard HTML table row attribute. Where we output content in a loop, it is good practice to apply this attribute and set it to a unique value within the loop so that React can distinguish it from the other elements.Omitting keys can also lead to performance problems on large datasetsas React will unnecessarily re-render the table when it doesn’t need to.
What does typescript do to regular javascript?
TypeScript adds an optional static typing layer on top of JavaScript that we can use during our development. Static types allow us to catch certain problems earlier in the development process.
What are two common npm dev dependencies to increase performance?
eslint and prettier.
What is an arrow function?
An arrow function is an alternative function syntax that was introduced in ES6. The arrow function syntax is a little shorter than the original syntax and it also preserves the lexical scope of this. The function parameters are defined in parentheses and the code that the function executes follows a =>, which is often referred to as a “fat arrow”.
What is the difference between let and const?
The const keyword can be used to declare and initialize a variable where its reference won’t change later in the program. Alternatively, the let keyword can be used to declare a variable whose reference can change later in the program.
What is the name given to an arrow function that has no parenthesis?
This is called an implicit return.
When implicit return is not an option? What prettier does in this case?
When an implicit return statement is over multiple lines, parentheses are required. When an implicit return is on just a single line, we can get away without the parentheses.
Prettier automatically adds parentheses in an implicit return if they are needed, so we don’t need to worry about remembering this rule.
What is an interface? Do interfaces exist in javascript? What about typescript?
An interface is a contract that defines a type with a collection of property and method definitions without any implementation. Interfaces don’t exist in JavaScript, so they are purely used by the TypeScript compiler to enforce the contract by type checking.
What is a type annotation?
Type annotations let us declare variables, properties, and function parameters with specific types. This allows the TypeScript compiler to check that the code adheres to these types. In short, type annotations allow TypeScript to catch bugs where our code is using the wrong type much earlier than we would if we were writing our code in JavaScript.
What is Emotion?
Emotion is a library that just helps us scope the CSS styles to specific components.
What is a template literal?
A template literal is a string enclosed by backticks (``) that can span multiple lines and can include a JavaScript expression in curly braces, prefixed with a dollar sign (${expression}). Template literals are great when we need to merge static text with variables.
What is a tagged template literal?
A tagged template literal is a template string that is executed through a function that is specified immediately before the template literal string. The function is executed on the template literal before the string is rendered in the browser.
What is the difference between a ts and tsx files?
ts is purely typescript and tsx is JSX typescript.
What is a styled component? Does it define the styles globally or for a specific component?
styled-components utilises tagged template literals to style your components. It removes the mapping between components and styles. This means that when you’re defining your styles, you’re actually creating a normal React component, that has your styles attached to it.
How does the css from Emotion is linked to a react component?
Emotion creates a random css class which is used in the given component… not the usual global css.
What is necessary to do with the React import when using Emotion?
To remove the react import and add the following header: /** @jsx jsx */