What are the major advantages of using ReactJS?
Below are some advantages of using ReactJS.
- Increases the application’s performance
- It is designed for the client-side and the server-side
- Because of the presence of JSX, code’s readability increases
- The language is easy to integrate with other frameworks like Meteor, Angular and more
- Writing UI test cases become extremely easy by using React
What is the difference between React Native and React?
What is Redux?
- Redux is designed to be only a single source of truth for your application state including a UI state like which tab is active or Data state like the user profile details. These data are retained by Redux in a closure that it calls a store. It also provides us with a recipe for creating the said store, namely createStore(x).
- The createStore function accepts another function, as an argument and is responsible for returning the state of the application now, which is then persisted in the store and is called as the reducer.
What is Redux Thunk used for?
Redux thunk is middleware that allows us to write action creators to return a function instead of an action. The thunk can then be used to delay the dispatch of action if a certain condition is met. This allows us to handle the asynchronous dispatching of actions. The inner function receives the store methods dispatch and getState as parameters.
Explain the components of Redux.
Redux is composed of the following components:
- Action: They are payloads of information that send data from our application to our store. They are the only source of information for the store. We send them to the store using store.dispatch(). Primarily, they are just an object explaining the activities in our app.
- Reducer: They specify how the application’s state changes in response to actions sent to the store. Actions only describe what happened, but don’t describe how the application’s state changes wherein this place determine how a state can change to action.
- Store: It is the object that brings Action and Reducer together. The store includes responsibilities like Holds application state; Allows access to the state via getState(); Allows the state to be updated via dispatch(action); Registers listeners via subscribe(listener) and Handles unregistering of listeners via the function returned by subscribing (listener).
We only have a single store in a Redux application, when you want to split your data handling logic, we’ll use reducer composition instead of many stores.
Can you state the difference between state and props?
The state is a data structure that begins with a default value when a Component mounts. It can be mutated across time, majorly as an outcome of user events. Props or Properties are a Component’s configuration that demonstrates the communication between the components.
They are received from the above component and immutable as far as the Component receiving them is concerned. A Component cannot change its props, but it is responsible for putting together the props of its child Components. There is also the case that we can have default props so that props are set even if a parent component doesn’t pass props down.
What is a higher-order component?
- A higher-order component (HOC) is an advanced technique to React for reusing component logic. HOCs are not part of the React API.
- It is a pattern that emerges from React’s compositional nature.
- A higher-order component is a function that takes a component and returns a new component.
- They allow you to reuse code, logic and bootstrap abstraction.
- They are common in third-party React libraries.
- Beyond simply sharing utility libraries and simple composition, HOCs are the best way to share behaviour between React Components.
What is create-react-app?
Create-react-app is the official CLI (Command Line Interface) for React to design React apps with no build configuration. You don’t have to install or configure tools like Webpack or Babel as they are preconfigured and hidden to focus on the code. It can be easily installed just like any other node modules.
It includes everything we need to build a React app:
- React, JSX, ES6, and Flow syntax support.
- Language extras beyond ES6 like the object spread operator.
- Autoprefixed CSS, so you don’t need -WebKit- or other prefixes.
- A fast interactive unit test runner with built-in support for coverage reporting.
- A live development server that warns about common mistakes.
- A build script to bundle JS, CSS, and images for production, with hashes and source maps.
How Virtual-DOM is more efficient than Dirty checking?
In React, each of their components has an observable state. Essentially, React comprehends the timings to re-render the scene as it can observe the data changes. On the contrary, Dirty checking is slower than observables because we must poll the data at a regular interval and check all of the values in the data structure recursively.
By comparison, setting a value on the state will signal to a listener that some state has changed, so React can simply listen for change events on the state and queue up re-rendering.
The virtual DOM is used for efficient re-rendering of the DOM which isn’t entirely related to dirty checking the data. In this case, we can re-render using a virtual DOM with or without dirty checking. In fact, the diff algorithm is a dirty checker itself.
We aim to re-render the virtual tree only when the state changes. So using an observable to check if the state has changed is an efficient way to prevent unnecessary re-renders, which would cause lots of unnecessary tree diffs. If nothing has changed, we do nothing.
Name the Popular Flux Libraries.
Flux is a general pattern for enforcing data flow through an application. There exist many implementations from which to choose from. There are nuances between each implementation, as well as specific pros and cons to consider. The candidate should provide examples of real-world experience using Flux.
- Redux: The most popular Flux library
- Alt.js: Another widely used library for managing data in React applications
To learn more about react, click here.