REACT / REDUX Flashcards
What is React? When and why would you use it?
React is a component based front-end framework that gives us the power to efficiently manipulate the DOM and create interactive User Interfaces. React, like other front end frameworks, allows the developer to manipulate the DOM with significantly less code while also creating a system that makes it easier to organize and manage various parts of the UI. React does this in a unique way by treating each UI element as a separate component that integrate the JavaScript, HTML, and CSS in one place in order to make the intended rendered element easier to manage and even reuse throughout the application.
What is Babel?
Babel is a transpiler that will take any javascript code and convert it into an older version of the code in order to manage any problems that may arise with older browsers. It also has the powerful benefit of working with JSX code, making it an essential tool for building React apps which are all a combination of HTML and JavaScript (which the browser can’t read).
What is JSX?
JSX is a JavaScript extension that combines JavaScript and HTML syntax in the same document. It is used in React as the main way to create components which are a bundle of the visual aspect (the HTML) and the logical (the JavaScript). JSX is not readable by any browser, so a transpiler like Babel will be necessary in order to view the page. Because of this, when using Babel, JSX code will be readable by nearly every browser.
How is a Component created in React?
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen. Components have properties (immutable data that can be used in rendering the component) and state (mutable data that is managed by the component itself). A component may also have various effects (defined within the function) and hooks (usually defined outside the function and even in separate files).
What are some difference between state and props?
the major difference is that props are immutable while state is mutable. Props are either defined by default or passed in by parent components, while state is defined and managed within the component.
What does “downward data flow” refer to in React?
Downward data flow is the concept in React that data can only be passed from parent components to child components, not the other way around. This can make React apps a bit easier to comprehend and debug since there will always be a sort of “nested” direction of data flow.
What is a controlled component?
a controlled component is any element whose state is controlled by the React state. For example, HTML form inputs are often maintaining their own state dependent on what a user inputs. In order to control this, we would need to set the value of these inputs to the state in React and update that value only when some setState function has been used to rerender the component. This is usually done with some sort of handleChange
function that sets react state onChange
(any time the input value changes).
What is an uncontrolled component?
an uncontrolled component is one that stores changes in the HTML DOM instead of in Reacts virtual DOM. This usually means that React will set the original state with a defaultValue
tag and use a “ref” in order to hold on to and utilize that data.
What is the purpose of the key
prop when rendering a list of components?
the key prop is crucial for react to know which components have actually been manipulated, especially in a list of components that are mostly or event completely the same. The key must be unique for each component in order to accomplish this. The key prop is used by React, but will not be usable as a prop for the developer or even seen by the final rendered DOM at all.
Why is using an array index a poor choice for a key
prop when rendering a list of components?
using the array index can be cause issues in the way React interacts with the components if the order of the list eventually changes for any reason.
Describe useEffect. What use cases is it used for in React components?
useEffect is a useful hook in react that allows you to program in a side effect of an action that will run after the component is rendered. These effects will run after the first render and after every subsequent render unless defined by the second argument which is an array of state. This array of state is used to inform the effect to only run after one or more of those pieces of state has been updated. These can be useful for doing an initial AJAX request when the item first renders or for updating a separate piece of state when the first is changed (i.e. counters or toggles).
What is the purpose of the React Router?
React Router gives the ability for our website to appear to work like a traditional website with multiple pages and url addresses, but it is actually a single page application. It provides functionality for the URL bar, bookmarks, and back/forward buttons.
What is a single page application?
This is an app that serves all the HTML that the client sees from one static HTML page that is manipulated by the JS. This usually means that any routing in the app will be done on the client side and no actual server requests will be made to generate the page when changing routes.
What are some differences between client side and server side routing?
With server-side routing, HTML is rendered by the server upon each HTTP request from the client. With client side routing, all routing and HTML rendering in the application is handled by the JavaScript on the client side and requests to the server tend to only return JSON instead of HTML.
What are two ways of handling redirects with React Router? When would you use each?
with React Router, there is a Redirect
component that simply re-routes the user to a chosen route and can be used in the Route
components or in the return statement of another component. This is mostly useful when a user attempts to go to a route that is protected or does not exist. There is also a history object that we have access to with the useHistory
hook in ReactRouter that will send the user to this new route and add it to the browser history ( -history.push("/redirect-route")
-). This is more usefull as a final action inside of a callback function ( -i.e. when a form is submitted so the user can be redirected if the submit is successful -).