Case Study
Case Study
React.js
This library allows you to place HTML code inside JavaScript and it
works with Virtual DOM.
Why react
1) Easy to learn
React is easy to learn and that is one of the most important reasons
to choose this library. As it doesn’t take much time to learn this
technology, you can quickly begin to build things with it.
2) Rich user-interfaces
3) Faster development
React is hot and trending. It’s one of the most popular frontend
technologies in the market.
Future of React.js
Step 1: Install NodeJS. You can download the form their official website of NodeJS.
Download and install the latest version of NodeJS.
Display App Directory :
Step 4: Start the development server. To start the development server, go inside
your current directory “myapp” and execute the below command:
npm start
Features of React
Problems in React
The name of each React part should start with a capital letter in any case
assuming we utilized that segment, the program will regard that segment as an
implicit component like range or div, and you may get the admonition. To
avoid this kind of warning, always start the React component name with the
upper case letter.
For example
// ...
}
If you try to render <greeting />, React will ignore the above and you will get a
warning:
[WARNING]
The tag <greeting> is unrecognized in this browser. If you meant to
render a React component, start its name with an uppercase letter.
While indicating the class name of the component in React, new learners use
class rather than className and this gives them blunders. As class watchword
is as of now held in JavaScript and JSX is only an expansion of JavaScript that is
the reason React utilizes className rather than class.
. Wasted rerenders
There are many ways, but one of the simplest is through “props” (data passed
directly to the component).
Say there’s an element such as “Item” which may represent a single item on
the list. If there is a list of two items and developers want to pass a value that
is computed in the list to each one of the cards, they can do it this way:
The problem here is that each time “getNewValue” is called, each item of the
list is rerendered, which is a waste of resources as the value is always the
same.
The above example here is a dummy one in order for the example not to look
too complicate.
Source- brainhum.com
Wasted rerenders
In real life, developers could deal with complex data structures being
rerendered which visibly slow down the performance, e.g. messages in a group
chat – a large collection of elements that contain text, images, and quotes of
other messages.
The answer is: this is often a problem for the end-user as well.
A tool that greatly eases the pain of manually checking every rerender is “Why
did you render”.
render(){
return (
}
}
Source- brainhub.com
The fix for that is easy to implement, however, one needs to be careful not to
eliminate rerenders when they really need to happen.
Developers can use “PureComponent” which performs a shallow comparison
of arguments passed to a component with the previous values and then
decides if the component needs to rerender.
Quite often, however, this is not enough and developers need to manually tell
the components if they need to rerender by providing custom comparison
functions.
If the components are arranged in a way that observable data is set at the very
top of the screen’s hierarchy component then this practice may accidentally
cause a wasted rerender which happens each time a character is added to or
deleted from the input field that is located on the screen and connected to a
data provider such as Redux.
PureComponent or a React’s new feature of “React.memo” lets developers
prevent such situations.
to improve the app’s performance and avoid unnecessary rerenders use a
detection tool called “Why did you render” and implement necessary fixes. Try
“PureComponent”, a tool that determines if the component needs a rerender
and either lets it pass, or stops it.
Conclusion
At the end of the day, React only solves the UI problems
Teams should keep one thing in mind – React alone is only a UI library which is
rarely enough and is never sufficient when the application grows complex.
Complex projects often need a toolkit that could handle the app’s logic and
effectively manage the current state. Using React JS alone for that purpose will
only result in a bloated codebase that will become hard to manage. In such
cases, libraries like Redux or MobX might prove useful.