React Flashcards

(61 cards)

1
Q

What is React?

A

A popular client-side (front-end) web framework for building complex web applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where does React run?

A

In the client’s browser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does Next.js do?

A

It extends React to work on both the client and the server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a component in React?

A

A self-contained piece of code representing a region on a webpage, managing its own content, presentation, and behaviour.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What enables dynamic updates in React components?

A
  • React components can change their appearance and behaviour dynamically by manipulating the virtual Document Object Model (DOM).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the Virtual DOM?

A

A virtual representation of the DOM that React uses to determine efficient updates to the actual DOM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Single Page Application (SPA)?

A

A website built with one HTML page and updated dynamically using JavaScript (e.g. via React).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are React components similar to HTML?

A

They are expressed as nested collections of elements, like HTML tags.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the key difference between React components and HTML elements?

A

React components are reactive and dynamic; HTML elements are static.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Name three common HTML tags used in web apps

A

<div>, <input></input>, <table>
</table></div>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are some attributes used in <table> tags?

A

border, cellpadding, cellspacing, and inline styles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the limitation of static HTML pages?

A

They cannot respond to user input or change dynamically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does React improve on static HTML?

A

By using dynamic, programmable components instead of static tags.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are other popular front-end frameworks besides React?

A

Vue, Angular, and Svelte.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Node.js used for in React projects?

A

It allows JavaScript to run outside the browser, like on a server or local machine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is npm?

A

Node Package Manager, used to install and manage packages.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you check Node.js and npm versions?

A

Run: $ node –version
$ npm –version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you create a new React project using Vite?

A

Run: npm create vite@latest ecommerce-site – –template react

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is Vite?

A

A fast, modern build tool for front-end frameworks like React.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you install and start a development server in React?

A

Run: npm install
then
npm run dev

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the purpose of npm install?

A

It installs dependencies listed in the package.json file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What do the main files and directoriesin a React app contain?

A
  • index.html: The main HTML file.
  • package.json: Lists the package dependencies for the project. Used by npm install to determine which packages to install.
  • public: Contains static assets like images
  • src: Contains the source code of the application.
  • vite.config.js: Configuration file for Vite.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do you run scripts defined in package.json?

A

Using npm run


How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does npm run dev do?

A

Starts the Vite development server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does npm run lint do?
Runs ESLint to check code for errors and style issues.
26
What is App.jsx?
The main React component file of a project.
27
What is JSX?
JavaScript XML - a syntax extension mixing JavaScript with HTML-like code.
28
What does export default App mean?
It exports the App component so it can be used elsewhere in the project.
29
What happens when React sees a component tag in HTML?
It calls the function and renders the returned HTML.
30
What URL shows the running React project in development?
http://localhost:5173
31
How do you create a separate Button component in React?
Create a new file (e.g., ButtonComponent.jsx) with a function returning JSX for a button.
32
How do you use a custom component in App.jsx?
Import it and include it in the JSX like a normal HTML tag.
33
How do you install Tailwind CSS in a React project?
Run: npm install -D tailwindcss postcss autoprefixer
34
What does -D mean when installing packages?
It installs the package as a development dependency.
35
What does npx tailwindcss init -p do?
Generates Tailwind and PostCSS config files.
36
What file do you configure Tailwind’s content paths in?
tailwind.config.js
37
Where do you add Tailwind's @tailwind directives?
In the ./src/index.css file that was auto generated by Vite when we created our react app. In index.css, add: @tailwind base; @tailwind components; @tailwind utilities;
38
What are the three layers of Tailwind CSS?
Base, Components, Utilities.
39
What does the Base Layer in Tailwind do?
Provides low-level, foundational styles.
40
What is the Components Layer in Tailwind for?
Contains pre-designed component styles like buttons and forms.
41
What is the Utilities Layer in Tailwind?
Contains atomic, single-purpose utility classes for custom design.
42
How do you apply Tailwind after setup?
Run: npm run dev to rebuild and serve the app.
43
What does the updated App component do?
Returns JSX with nested components and displays the webpage UI.
44
What is a label in the context of React components?
A label is a prop used to pass data from a parent component (e.g., App) to a child component (e.g., ButtonComponent).
45
How is the label prop accessed inside a component?
By destructuring it in the function parameters: const ButtonComponent = ({ label }) => { ... }.
46
What are props in React?
Props are read-only attributes passed from parent to child components to make them reusable and dynamic.
47
What happens when a prop changes in a parent component?
Props are read-only attributes passed from parent to child components to make them reusable and dynamic. When a prop of a React component is changed by its parent component, the child component is re-rendered with the new prop value- when changed React recalls the function with the new value.
48
What is rendering in React?
Rendering is the process of turning React code into an actual webpage using JSX to create a virtual DOM. 1) function components return JSX 2) rendering a component begins with calling the components function 3) resulting JSX element used to create virtual DOM 4) virtual DOM updates the actual DOM
49
What does JSX stand for?
JSX stands for JavaScript XML and is a mix of HTML and JavaScript used in React components.
50
How does JavaScript import specific named exports?
Using curly braces: import { useState, useEffect } from react.
51
How is a default export imported in JavaScript?
Without curly braces: import React from react. When you don't have {} you import the default export and assign it to the name you used. When you use {} you import specific named exports and the name used is important.
52
What are React hooks?
Functions that let you use state and lifecycle features in function components. React provides built-in hooks including: - useState, useEffect, useContext
53
What does the useState hook do? What are the two values returned by useState?
It takes one argument, the initial state, and returns an array of two elements: - The first element is a value that always equals the current state. - The second element is a function that can be used to update the state. - Calling this function will cause the component to rerender with the new state value. State updates are performed asynchronously.
54
What does the useEffect hook do?
It allows you to perform side effects in function components based on dependencies. - It accepts two arguments: a callback function and an array of dependencies. - The callback function contains the side effect logic. - The array of dependencies is a list of variables upon which the effect depends. If any of these variables change, the effect will run again. - This allows you to control when your side effects run, ensuring they only run when necessary.
55
What does the useContext hook do?
Lets you subscribe to a context which contains data
56
What causes a component to re-render when using useState?
Calling the state update function returned by useState.
57
What does the useEffect dependency array do?
Controls when the effect runs by watching specified variables.
58
How are lists of JSX elements rendered in React?
Using array methods like map and filter to generate JSX elements and wrapping them in HTML tags like ul and li. - ul is an unordered list. - li is a list item.
59
What does the App component typically do in a React app?
Defines the top-level structure and manages state such as searchTerm using useState.
60
How is a search input typically handled in React?
With a Search component that uses an input element and updates state using a passed prop function.
61
How is a list of products rendered in a ProductList component?
By mapping over an array of products to generate JSX elements.