React
React
@himanshu_shekhar16
Reacts Most Asked Questions
● What is React js
● What is difference between virtual dom and shallow
dom, dom in React js
● What is controlled and uncontrolled component in
React js
● What is hooks in React js
● What is jsx, babel, webpack
● What is Redux
● What is reducer, action, store in Redux
● What is middleware in Redux
● Explain data flow in Redux
● What is Redux-Thunk
● What is Redux-Saga, Difference between
Redux-thunk and Redux-saga
● Difference between class component and function
component
● How can we implement componentWillUnmount in
function component
● useEffect,UseState, useMemo.useCallback hooks in
Details
● Explain lifecycle method in React js
● What is difference between export default and export
in React js
● What is portal in React js
● What is reconciliation in React js
● What is useRef in React js
● What is server side render in React js
● What is useStrict in React js
● What is fragment in React js
● What is react router in React js
● What is node module in React js
● What is the default localhost server port in react js.
how can we change the local server port
● What is high order component in React js
● What is pure component in React js
● What is difference state and props in React js
● How to optimize React js app
● What is difference between React js and Angular js
● What is prop drilling in React js how to overcome it
● What is context api in React js
● What is super, constructor, render function in React
What is React?
React is officially defined as a "JavaScript library for creating user interfaces,"
but what does that really mean?
The most basic JavaScript concepts you should be familiar with are variables,
basic data types, conditionals, array methods, functions, and ES modules.
How do I learn all of these JavaScript skills? Check out the comprehensive
guide to learn all of the JavaScript you need for React.
JavaScript is a 20 year old language which was created for adding small bits
of behavior to the browser through scripts and was not designed for creating
complete applications.
In other words, while JavaScript was used to create React, they were created
for very different purposes.
You can use any browser or window API, such as relocation or the fetch API.
Creating a React app on your computer using a tool like Create React App
If you want to create a complete web application that you want to ultimately
push to the web, it is best to create that React application on your computer
using a tool like Create React App.
If you are interested in creating React apps on your computer, check out the
complete guide to using Create React App.
The easiest and most beginner-friendly way to create and build React apps for
learning and prototyping is to use a tool like Code Sandbox. You can create a
new React app in seconds by going to react. New!
JSX Elements
JSX is a powerful tool for structuring applications
JSX is meant to make create user interfaces with JavaScript applications
easier.
JSX borrows its syntax from the most widely used programming language:
HTML
Attributes that consist of multiple words are written in the camel-case syntax
(i.e. className ) and have different names than standard HTML ( class ).
The reason JSX has this different way of writing attributes is because it is
actually made using JavaScript functions (more on this later).
Once again, the style properties that we use must be written in the camel-
case style.
One simple example if that to conditionally hide or display JSX content, we can
use any valid JavaScript conditional, like an if statement or switch statement.
return <button>Login</button>
Where are we returning this code? Within a React component, which we will
cover in a later section.
Both pieces of code will have the same output of "Hello React".
To write JSX and have the browser understand this different syntax, we must
use a transpiler to convert JSX to these function calls.
Components are created using what looks like a normal JavaScript function,
but is different in that it returns JSX elements.
Think of React components as our custom React elements that have their own
functionality.
Components are reusable wherever we like across our app and as many times
as we like.
Another rule is that JSX elements must be wrapped in one parent element.
Multiple sibling elements cannot be returned.
If you need to return multiple elements, but don't need to add another element
to the DOM (usually for a conditional), you can use a special React component
called a fragment.
Fragments can be written as or when you import React into your file,
with <React.Fragment></React.Fragment> .
There are a few core rules to using dynamic values within JSX, however.
JSX can accept any primitive values (strings, booleans, numbers), but it will
not accept plain objects.
For example, conditionals can be included within JSX using the ternary
operator, since it resolves to a value.
Props
Components can be passed values using props
Data passed to components in JavaScript are called props
Props are available in parameters of the component to which they are passed.
Props are always included as properties of an object
document.getElementById("root")
Another way to say this is that props should never be mutated, since props
are a plain JavaScript object
Components are consider pure functions. That is, for every input,
we should be able to expect the same output. This means we
cannot mutate the props object, only read from it.
The children prop is especially useful for when you want the same component
(such as a Layout component) to wrap all other components.