React Questions Flashcards
What is React?
A javascript library for building user interfaces. It uses a virtual dom, JSX, and components.
What is Redux?
Redux is a predictable state container for JavaScript apps.
It allows you to manage state for your web applications.
It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test.
On top of that, it provides a great developer experience, such as live code editing combined with a time traveling debugger.
Redux evolved from the idea of Flux — an architecture pattern created by the Engineers at Facebook.
How does Redux work?
The core concepts of Redux — Store, Actions, Reducers, and Subscriptions.
Initial State - what it looks like initially
Actions/Dispatches
Actions / Dispatch - Actions can alter the initial state. When we use an action we are dispatching.
Reducers - Interpret actions and update state accordingly. Reducers take in the argument of the state set to the default initial state and the action. This action helps the reducer determine what needs to be done with the state.
Store - This is where the state is contained. In order to create one, you need a reducer and initial state.
Subscribe - listens for store updates
What makes Redux so Special?
In short, Redux gives you a single object that holds the state for your entire application in one location — that could include data from your backend API or an external API, state for navigation, a user’s information, toggled state of a button, and so on.
This is powerful because it allows easier scalability and the ability to quickly diagnose bottlenecks, asynchronous issues, or errors.
Redux set up process
- Create a reducers folder, reducers.js inside.
- inside reducers.js define defaultState and a reducer function
- default state includes the fields we want to store
- reducer function takes state and an action as arguments.
- The action itself is represented as an object with two keys. action and payload.
- use a switch statement to determine what to do for each action
- Implement Redux in the index.js file
- import {Provider} from ‘react-redux’;
- import {createStore} from ‘redux’
- import reducer from ‘./reducers/reducer’
- Connect the Component
- connect the components we want to the store we created in index.js
- import {connect} from ‘react-redux’
- export default connect()(App) - Map State to Props
- Once we establish a connection, let’s add state as props to this component. Within the App component, let’s create a function called mapStateToProps. - Map Dispatch to Props
- Now, let’s change values in state. We set up another function inside App called mapDispatchToProps.
- Similar to mapStateToProps, we return an object but with the key of setUser set to a value of a function that will send a dispatch to the reducer.
- In this instance, when we call setUser through props, it expects a user object argument that uses the callback function, dispatch.
What are reducers in redux?
a reducer is a pure function that takes an action and the previous state of the application and returns the new state.
Why do you choose React?
It’s a very popular framework with a lot of employment opportunities. Doesn’t seem to be going anywhere anytime soon, so decided to pick this one.
What is AJAX?
AJAX = Asynchronous JavaScript And XML.
Axios let’s us take advantage of this.
It allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes.
- You can read data from a web server after a web page has loaded
- Update a web page without reloading the page
- Send data to a web server - in the background
What is reponsive design?
Responsive Web design is the approach that suggests that design and development should respond to the user’s behavior and environment based on screen size, platform and orientation.
What is Restful API?
A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer and was created by computer scientist Roy Fielding.
An API is a set of definitions and protocols for building and integrating application software. It’s sometimes referred to as a contract between an information provider and an information user—establishing the content required from the consumer (the call) and the content required by the producer (the response). For example, the API design for a weather service could specify that the user supply a zip code and that the producer reply with a 2-part answer, the first being the high temperature, and the second being the low.
In other words, if you want to interact with a computer or system to retrieve information or perform a function, an API helps you communicate what you want to that system so it can understand and fulfill the request.
You can think of an API as a mediator between the users or clients and the resources or web services they want to get. It’s also a way for an organization to share resources and information while maintaining security, control, and authentication—determining who gets access to what.
Another advantage of an API is that you don’t have to know the specifics of caching—how your resource is retrieved or where it comes from.
What is the difference between REST API and RESTful API?
REST stands for representational state transfer. It is a set of constraints that set out how an API (application programming interface) should work. If an API is RESTful, that simply means that the API adheres to the REST architecture. Put simply, there are no differences between REST and RESTful as far as APIs are concerned. REST is the set of constraints. RESTful refers to an API adhering to those constraints. It can be used in web services, applications, and software.
There are 4 main principles of REST as laid out by Roy Fielding and his colleagues in 2000. They set out to create a standard that allowed servers to communicate with other servers easily. This is what they came up with, changing the landscape of APIs:
Client-Server: There is always a client and a server, and these two systems need boundaries for how they operate. Which one is being called (server) and which one is making the request (client)? Having these boundaries leads to smoother operation.
Stateless: Servers need to be able to process messages they receive. In order to do this, every request a server receives should have the necessary information required for the server to work.
Uniform Interface: Using similar terminology and resources helps standardize APIs. According to this principle, the following HTTP verbs are used: GET, PUT, POST, and DELETE. Resources always refer to URIs (uniform resource identifier). HTTP responses always come with a status and a body.
Cacheable: Clients need to be able to cache representations. Because of statelessness (every representation being self-descriptive), this is possible in a RESTful API.
What is the point of RESTful API?
A RESTful API is an architectural style for an application program interface (API) that uses HTTP requests to access and use data. That data can be used to GET, PUT, POST and DELETE data types, which refers to the reading, updating, creating and deleting of operations concerning resources.
What is closure?
A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.
What is promise?
A promise is an object that may produce a single value some time in the future : either a resolved value, or a reason that it’s not resolved
What is callback?
A callback function is a function passed into another function as an argument,
What are the major features of React?
- Virtual DOM (speeds up dev process)
- Javascript XML or JSX
- React Native (transforms code to IOS Android compatibility)
- One-Way Data Binding
This means that React uses a flow of data that is unidirectional, forcing developers to use the callback feature to edit components, and preventing them from editing them directly.
The controlling of data flow from a single point is achieved with a JS app architecture component called Flux. It actually affords developers better control over the app and makes it more flexible and effective.
- Declarative UI
This feature makes React code more readable and easier to fix bugs. React JS is the best platform to develop UIs that are both exciting and engaging not just for web apps, but mobile apps as well.
- Component Based Architecture
This simply means that the user interface of an app based on React JS is made up of several components, with each of them having its particular logic, written in JS.
Due to this, developers can relay the data across the app without the DOM being impacted. React JS components play a huge part in deciding the app visuals and interactions.
What is JSX?
Javascript in React. Separates Concerns via components. Create components to simplify UI rendering (separate logic)