Introduction Flashcards
What is React?
A library for creation of “composable” UI components using Javascript and XML.
What are the main advantages of React?
- Reactive Rendering
- Composable Components
- Abstracted Document model
What is a React component ?
In simpler terms a React component is nothing but the Javascript class, which must have a “render” method which returns the description of “Component’s UI”.
This description will be in JSX format.
Write the general syntax of React component?
class Hello extends React.Component { render () { <h1> Hello World </h1> } }
How React allow us to write “tags” (html/xml”) inside the Javascript code? How browser understands this JSX?
React uses JSX (Javascript extension) for writing the UI components. By this way, we can add tags (xml or html) inside the components.
The browser doesn’t understands this JSX, hence we need a trans compiler which transforms the JSX code into Javascript.
What’s the shortest way to bootstrap a react application?
By using “create-react-app” package.
npm install -g create-react-app
What is npx?
NPX is the package which gets automatically installed, when we install the npm.T he npx is used to run the “npm packages”.
How to use npx to create a react based project?
npx create-react-app todo
What is the package/directory structure created by the create-react-app?
Whenever we create any project using “create-react-app”, it creates the following directory structure:
- public directory
- src directory
- package.json
- .gitignore file
What’s the purpose of “public/index.html” file created by the create-create-app utility?
“index.html” is the main file loaded in user’s browser, whenever a user hits the application.
It contains the “root” element which will contain the entire application.
What’s the purpose of “src/index.js” file created by the create-create-app utility?
This is the main “javascript” file, which is responsible for starting the react application in user’s browser.
This file is also responsible for configuring the react application.
What’s the purpose of “src/app.js” file created by the create-create-app utility?
This is nothing but the react component, which contains the “html” content which will be displayed to the user. It also contains the “javascript” file required for the content.
what is main difference between npm and npx?
npm is used to install packages.
npx is used to execute packages.
In react based development, npx is only used when we need to create a new “project”, rest all other package management is done by “npm”.
How to add “bootstrap” library to you react application?
- Install bootstrap to your project:
npm install bootstrap - Import bootstrap css in index.js
import ‘bootstrap/dist/css/bootstrap.css’
How to start the react application?
npm start
What is the difference between “render” and “return” inside a React Component?
Render is the lifecycle function, which is called whenever a component is updated.
Return is used to return the “react element” in JSX format.
How a react element is returned by the component?
A react element is returned from the “render” method inside the Component class.
It returns the “react element” which is displayed to the user.
e.g. return (
<div> <p> my react element </p> </div>
)
What is a “react element”?
A react element is nothing but the “html element” which is visible to the user.
What’s the main different between import and require?
“require” and “modules.export” is CommonJS feature.
“import” and “export” is ES6 feature.
How to use import/export, if we are using the CommonJS?
We need to use the “transcompiler” like Babel, which transcompiles the code into ES5.
Write the general syntax of React component?
React component is just a class, which contains the render function.
import React, { Component } from ‘react’;
export default class App extends Component { render () { return ( <div class="root"> <p> hello world </p> </div> } }
How to provide “class” attribute to HTML element in JSx?
It is done by using “className” attribute.
What will happen, if we use “plain” HTML attributes in react element instead of JSX attribute?
We will get error inside the console with name “Invalid DOM property”.
What is an expression inside the react component?
The expression is the mechanism, which gets evaluated to a “value” whenever a component is called. It is always written inside “curly braces”.
e.g. { this.state.data }