3) React Basics Flashcards
command for creating a react app?
npx create-react-app app-name
command script translation: react-scripts build
converts code from the src folder and fitting a lighter version of that code into the public folder.
command script translation: react-scripts build
creates a react app
command script translation: react-scripts test
runs the test code
command script translation: react-scripts eject
reveals the configuration code for Babel and webpack so that we can manage it ourselves
What project folder actually contains the files that we wll deplooy to a server?
public
What does the React library allow us to do?
We can write html like syntax in javascript files
You should never use the eject script until …
you have to
biggest advantage class components have over function components
state and lifecycle methods
JSX syntax for a button that changes a string state property onClick
this.setState({ string: “Abeche” })}>
What counts as a javascript expression inside of JSX?
Anything between curly braces
what property name does JSX use for html classes? why?
className
because class already means something in javascript
What method must you use to modify state in react? why?
this.setState()
it alertts the reactDOM that a change has been made
what does the map() method do?
returns the return of whatever function passed into it, iterated over each element in the array.
Why does react need each element in a state property array to have a unique ID
react needs to know which element to change if one of them changes so that it does not have to re-render everything.
what is the purpose of this line:
class App extends Component {
component is an object that we get from react that comes with useful functionality.
what is this called? (component):
import React, { Component } from “react”;
destructuring
Single page applications request ___ instead of ___
data instead of entire pages
What makes SPA so fast?
re-rendering the page is handled by javascript more so than server requests.
where do lifecycle methods come from?
the Component object from React.
What are lifecycle methods?
methods that get called at different stages of when the component gets rendered.
what does the componentDidMount() method do?
calls whatever code is inside of it when the component is rendered onto the DOM for the first time.
What is the significance of the bold code?
componentDidMount() {
fetch(“https://jsonplaceholder.typicode.com/users”)
.then((response) => response.json())
.then((users) => console.log(users));
}
presents the fetched data as a .json object (new promise) which allows us access to the information that we want.
steps for assigning API data to a state attribute? (3)
- fetch the data
- convert data to json
- save that json data to the state using setState()
What kind of parameter does the setState method take?
an JS object
When a component relies on API data, the state attribute for that data should be initialized as …
an empty array
What are the two ways of building components in React?
classes
functions
Where do the props that the components receive come from?
properties passed into the component tags:
ex. <cardlist></cardlist>
what is the .children attribute of the props object?
anything in between the component tags:
ex.
<cardlist></cardlist>
# Che