Week 7 Flashcards
What is React? Is it a library or framework? What’s the difference between those?
React is a UI library. It’s a library not a framework because you call it in your code; it can be integrated into part of or the entire UI
Why use React?
- We use it to make single page front end applications
- Lets us dynamically create and render components without having to refresh pages
What is the difference between React and ReactDOM?
React is a higher level package for both ReactDOM and React Native
ReactDOM is strictly the web implementation of React
How many HTML pages does our React App use?
We render in one SINGLE page
It is constructed in a way that we only ever need to render one DOM object
What is SPA?
Single Page Application is a website design approach where each new page’s content is served not from loading new HTML pages but generated dynamically with JS’s ability to manipulate the DOM elements on the existing page itself
What are some benefits of SPA?
Allows users to contineu consuming and interacting with the page while new elements are being updated or fetched, and can result in much faster interactions
What are some downsides of SPA?
Accessibility
SEO rankings
If your content is purely static, it can worsen initial load times
What is the package.json?
Lists our dependencies
Lists our scripts
Start, test are aliases for npm run [script]
Run the build script to show the target folder
What are node_modules?
Houses our dependency files
What is gitignore?
Auto-generated by create-react-app to prevent us from pushing certain things to github repos
What is the build folder?
After running the command npm run build a folder called build is created with our self-container app
What is ReactDOM.render?
ReactDOM takes 2 arguements
The element to render
The location to add the element to in the DOM
What is react.createElement?
react.createElement(“h1”, { style: { color: “blue” }}, “Hello world from react”)
What is the App.tsx? Why do we structure it in that way?
Main entrypoint for our application
This is where we render the root node for the DOM object
“A lot” of the time this is where we do our app routing
It’s structured like this because easy to maintain and at the end of the day we only want one root for everything else
What are the roles of Babel and Webpack?
Babel
Free open source JS transpiler or transcompiler that will turn things like JSX and tsx into valid JS code
Make sure to start all components with capital letter, this is how Babel knows its a component it has to transpile
Webpack
This is a packaging tool that takes all the different files and modules and build them into a web package to use within the browser
What does it mean to be component-based? What does a component represent?
Components are reusable parts of the UI that maintain a state and get rendered to the page
Tell me how you would start up a new React project? What does ‘create react app’ setup for you?
You should use npm to install react and any other dependencies
How would you create a component?
Create either a JS class or function
Why use components?
Increase reuseability and maintainability
Also helps loosen code coupling within the application
What does a component have to render/return?
A component must return/render a JSX view of some type
This view can only have one single root JSX tag
What are “props”? What is state? What data should be put in which?
Props are readonly; they are passed into the component
State is the immutable object representing the current state of the component
What is the lifecycle of a component?
Constructor - use for initializing state
render() - returns the JSX to be compiled and rendered onto the browser
componentDidMount() - runs once, after the component is rendered
componentDidUpdate() - runs after every update of the component
componentWillUnmount() - runs before the component is removed from the DOM
What is the difference between a functional and a class component?
Functional - before hooks, could not modify state and only used as ‘display’ component
Class - utilizes lifecycle methods and render method
What are React hooks? How do we use them?
React hooks are functions we can call in order to access certain functionalites
They all start with use such as useStyle(), useState(), useEffect()
We call them hooks because they allow us to hook into certain aspects of a component whether it be style or lifecycle
What is useState()?
is a function that returns an array of the following
Index 0, we have the state object
Index 1, we have the function to use to update that object state
What is useEffect()?
Allows us to manage side-effects that aren’t related to rendering the component
Takes in 2 params
A callback function denoting what action you want to perform
A dependency array of state values that act as triggers for the action on change