React 1
React 1
React 1
www.codaroo.io
@) codaroo.io eBook
The Reacting Point - Codaroco.io eBook
Our goal is to cover the most frequent questions that pop-up on React
interviews. In addition to that, we are providing the answers that are deep-
enough to understand. We are also providing the resources that will help
you dive even deeper.
Ths eBook will evolve as we grow, as technology changes and with your
feedback. This is the first version of this eBook.
As a bonus, at the end of this eBook you will find links to resources where
you will be able to find remote React jobs.
Thank you!
The Reacting Point - Codaroco.io eBook
Virtual DOM works by comparing the current virtual DOM tree with a new
virtual DOM tree, and then applying the minimal set of changes to the actual
DOM. This allows React to efficiently update the user interface without
causing unnecessary re-renders or layout changes.
The Reacting Point - Codaroco.io eBook
fr fs dae
fy £3 dr
Real DOM is the actual tree-like structure of a web page, which can be
manipulated directly to change the layout or content of the page. Virtual
DOM is a lightweight in-memory representation of the actual DOM, which is
used to optimize the performance of updates to the user interface.
9. What is reconciliation?
Reconciliation is the process that React uses to determine the minimal set
of changes to be made to the actual DOM. It compares the current virtual
DOM tree with a new virtual DOM tree, and then applies the minimal set of
changes to the actual DOM.
The Reacting Point - Codaroco.io eBook
Update
Reconciliation
New Virtual
DOM Browser DOM
(§ Diff
When a component's state or props change, React will create a new virtual
DOM tree, compare it to the previous tree, and then apply only the minimal
set of changes necessary to the actual DOM. This improves the
performance of the application and reduces the number of unnecessary re-
renders.
Class components in React are defined using the ES6 class syntax. They
have access to state and lifecycle methods and are used for more complex,
stateful components.
State in React is an object that holds data that can change, and it is
managed by a component. It is used to store and update the component's
cata and can be passed down to child components as props.
State can be updated using the setState method, which triggers a re-render
of the component, updating the user interface.
Props in React are used to pass data from a parent component to a child
component. They are essentially a way to pass data and methods down the
component tree. Props are read-only, meaning that they cannot be modified
by the child component.
The children prop is a special prop that is used to pass children elements to
a component. It is used to pass elements between components, such as a
list of items or a set of nested components.
The Reacting Point - Codaroco.io eBook
To create a props proxy for an HOC component, you can use the
React. forwardRef function. This function allows you to pass props
through to the wrapped component, preserving the original component's
props.
To update state in a React class component, you can use the setState
method. This method takes an object or function as an argument, and it will
merge the new state with the existing state.
State is the internal data of a component that can change and is managed
by the component itself. Props are external data passed to a component
from its parent component. State can be updated by the component,
whereas props cannot be updated by the component.
React Hooks are functions that allow you to use state and other React
features in functional components. They were introduced in React 16.8.
The useEffect hook allows you to run side effects, such as fetching data or
updating the DOM, in a functional component. It takes a callback function as
its first argument, which is called after the component has rendered. Here's
an example of how to use the useEffect hook:
MyCompone
[data, Datal
useEffect(() {
fetchbData( )
i. name }</p=
The useEffect hook is used to run an async function fetchData that fetches
data from an API and updates the component's state with the result. The
empty array [] passed as the second argument to useEffect means that the
effect will only run once, when the component is first rendered.
The useEffect hook allows the component to update its state and re-render
in response to changes in some variable. In this case, when the component
is first rendered, the data is fetched and the component re-renders with the
updated data.
The Reacting Point - Codaroco.io eBook
MyComponent( )
[a, seth]
[b B]
MyComponent ;
In this example, the useMemo hook is used to memoize the result of a costly
calculation that depends on the values of a and b. The useMemo hook takes
two arguments: the first is a eon that performs the calculation, and the
The component has two input fields, where the user can set the values of a
and b. When either of the inputs change, the component re-renders, but the
result is only recalculated if a or b have changed, which is determined by
the dependencies array [a,b].
This prevents the costly calculation from being performed every time the
component re-renders, improving the performance of the application.
The Reacting Point - Codaroco.io eBook
React, { useRef }
MyComponent() {
inputRef = useRef(
handleClick() {
inputRef.current.value = "Hello World!";
MyComponent ;
To create a ref, you can use the useRef hook, which returns a ref object.
You can then assign this object to a ref attribute on a JSX element.
The Reacting Point - Codaroco.io eBook
React, { forwardRef } 3
input type='
Component ref
ick={ha
Yes, you can create your custom React hooks by following the naming
convention "use" and using state and other hooks inside it.
When creating custom React hooks, it's important to keep in mind that they
should only call other hooks at the top level and not inside loops or
conditions.
Also, it's important to make sure that the hook only performs one specific
action.
The Reacting Point - Codaroco.io eBook
The Context API in React allows you to share data between components
without passing props through every level of the component tree. It
provides a way for components to access data that is "global" to the
component tree, such as a user's authentication status or a theme.
The Context API consists of a Provider component, which provides the data,
and a Consumer component, which accesses the data.
React Router is a library for routing in React apps. It allows you to define the
different routes in your application and render the appropriate components
for each route. This makes it easy to change the displayed content based
on the current URL, without having to refresh the page.
Pure components are components that only re-render if their props or state
have changed. They are optimized for performance, and they can improve
the performance of your application by reducing the number of
unnecessary re-renders.
No, you cannot update the React state directly. You should always use the
setState method to update the state, which will trigger a re-render of the
component.
The "key" prop is used to give a unique identifier to each item in an array of
elements. When elements are re-rendered, React uses the key to identify
which elements have changed, added, or removed. This allows React to
update the DOM efficiently, improving the performance of the application.
The lifecycle methods of React are methods that are called at specific
points during the lifecycle of a component. They include:
The purpose of using the super (props) constructor with the props
argument is to call the constructor of the parent class and pass in the
props. It is necessary because the parent class's constructor sets up the
initial state and props of the component and must be called before the child
class's constructor.
React uses the className attribute instead of the class attribute because
class is a reserved keyword in JavaScript. Using className avoids any
confusion and ensures that the attribute will be interpreted as intended.
The Reacting Point - Codaroco.io eBook
Fragments are better than container divs because they don't add an extra
node to the DOM. This can make the rendered HTML cleaner and more
efficient, especially when you have a component that renders a list of items.
Additionally, it helps with accessibility because it doesn't create an
unnecessary wrapper element around the content.
The react-dom package is a package that provides the renderer for React
components. It provides the functions that are used to render React
components on the web (DOM).
If you use setState in the constructor, it will cause the component to re-
render before it is added to the DOM. This can cause unexpected behavior
and should be avoided. Instead, it is recommended to initialize the state
with the constructor's props and use setState in componentDidMount.
* constructor()
* static getDerivedStateFromProps()
* render ()
* componentDidMount ()
The lifecycle methods that are going to be deprecated in React v16 are:
* componentWillMount
* componentWillReceiveProps
* componentWillUpdate
componentWillReceiveProps()
The Reacting Point - Codaroco.io eBook
React and ReactDOM are separated to allow for better flexibility in different
environments. React can be used to build user interfaces on the web, on
mobile, or on desktop without having to change the core library. ReactDOM
provides the specific methods needed to render components on the web.
Yes, it is possible to use React without rendering HTML. React can be used
to build user interfaces for other environments such as native mobile apps
or virtual reality. React Native and React VR are examples of libraries that
allow you to use React to build apps for those environments.
You can't update props in React because they are passed down from a
parent component and are considered to be immutable. Instead, you should
use state to manage data that can change within a component, and pass
that data down to child components as props.
The Reacting Point - Codaroco.io eBook
To focus an input element on page load, you can use the ref property to
create a reference to the input element, and then call the focus () method
on that reference in the componentDidMount () lifecycle method.
To programmatically trigger a click event in React, you can use the ref
property to create a reference to the element, and then call the elick()
method on that reference.
There are various bundlers such as webpack, rollup, parcel, and browserify.
« |t can make debugging more difficult because the state is not visible
in the components
« |t can lead to verbose and repetitive code because actions and action
creators are separate files
React context is a built-in feature of React that allows you to share data
between components without having to pass props down through multiple
levels of the component tree. React Redux is a library that allows you to
connect your React components to a Redux store. It provides a way to
access the state from the store and to dispatch actions to modify the state.
The Reacting Point - Codaroco.io eBook
Redux state functions are called reducers because they are used to reduce
the current state and an action to the next state. The reducer takes the
current state and an action as input and returns the next state.
Redux Thunk is a middleware that allows you to write action creators that
return a function instead of an action. This function can then be used to
perform async logic and dispatch other actions.
It's generally not good to use arrow functions in the render method because
they create a new function on every render, which can negatively impact
performance. If a component uses an arrow function in its render method, it
will re-create that function on every render and cause the component to re-
render even if its props haven't changed.
Yes, it is possible to use React without JSX. React provides a way to use
JavaScript to create elements, and you can use JavaScript to create the
same elements that you would create with JSX.
The Reacting Point - Codaroco.io eBook
Try catch block works with imperative code whereas error boundaries are
meant for declarative code to render on the screen.
You can use the useEffect hook to fetch data in a React functional
component. The useEffect hook allows you to run a side effect, such as
fetching data, after the component has rendered. You can also use
useState to store the fetched data and update the component when the
data is available.
The ESLint plugin for hooks is a set of rules that enforces the rules of hooks
as specified by the React team. It helps to prevent common mistakes and
inconsistencies when using hooks. It also helps to make sure that hooks are
only used in functional components and that they are called in the correct
order.
The Reacting Point - Codaroco.io eBook
Bonus
« htips://remoteok.com/
« htips://weworkremotely.com/
« https://www.workingnomads.com/jobs
+ https://angel.co/
+ https://remote.co/
« htips://remotive.com/
« htips://powertofly.com/
« https://authenticjobs.com/
+ htips://euremotejobs.com/
« htips://www.flexjobs.com/
« htips://nodesk.co/remote-jobs/