What Is React
What Is React
What Is React
What is Props?
i. componentWillMount() – Executed just before rendering takes place both on the client as
well as server-side.
ii. componentDidMount() – Executed on the client side only after the first render.
iii. componentWillReceiveProps() – Invoked as soon as the props are received from the parent
class and before another render is called.
iv. shouldComponentUpdate() – Returns true or false value based on certain conditions. If you
want your component to update, return true else return false. By default, it returns false.
v. componentWillUpdate() – Called just before rendering takes place in the DOM.
vi. componentDidUpdate() – Called immediately after rendering takes place.
vii. componentWillUnmount() – Called after the component is unmounted from the DOM. It is
used to clear up the memory spaces.
What is Redux?
i. Single source of truth: The state of the entire application is stored in an object/ state tree
within a single store. The single state tree makes it easier to keep track of changes over time
and debug or inspect the application.
ii. State is read-only: The only way to change the state is to trigger an action. An action is a
plain JS object describing the change. Just like state is the minimal representation of data, the
action is the minimal representation of the change to that data.
iii. Changes are made with pure functions: In order to specify how the state tree is
transformed by actions, you need pure functions. Pure functions are those whose return value
depends solely on the values of their arguments.
Predictability of outcome – Since there is always one source of truth, i.e. the store, there is
no confusion about how to sync the current state with actions and other parts of the
application.
Maintainability – The code becomes easier to maintain with a predictable outcome and strict
structure.
Server-side rendering – You just need to pass the store created on the server, to the client
side. This is very useful for initial render and provides a better user experience as it optimizes
the application performance.
Developer tools – From actions to state changes, developers can track everything going on
in the application in real time.
Community and ecosystem – Redux has a huge community behind it which makes it even
more captivating to use. A large community of talented individuals contribute to the betterment
of the library and develop various applications with it.
Ease of testing – Redux’s code is mostly functions which are small, pure and isolated. This
makes the code testable and independent.
Organization – Redux is precise about how code should be organized, this makes the code
more consistent and easier when a team works with it
What is the difference between a stateless component and a stateful component in React?
There are several ways to optimize the performance of a React application, including: