ReactYoutubeNotes_9875df
ReactYoutubeNotes_9875df
We can write custom commands in the package.JSON file. Here I have mentioned ”filename” to start my json-server.
RCC for new class-based component. RFC for new function-based component.
React Fragment
Here the issue is I have declared a function “multiCount()” insdide the render
method. Where multicount function returns when count state update takes place.
But this function is also called with the change of Item state because the function
is defined in the middle of render Method without any condition. By this type code
the page will become slow and performance issues will be there.So to overcome
from this type of issue we can use useMemo hook.
Ref use in ReactJS(Class Based Component)
React tells to use Ref incase of emergency or in a very minimum way.
It always manipulate the DOM. If you will manipulate DOM then ReactJS will
become slow.
Below image shows how to use “Ref”
If you will go to browser and see the condsole will show all the properties of input
box. See the below image
Line number 16 can change the input text value into red after clicking the button.
Line number 17b can change the background color of input box after clicking
button.
Its not showing the defaultvalue because we have set the value={val}. Remove it
and it will show the defaultValue or by state array destructuring.
Uncontrolled Component in ReactJS
Uncontrolled means we are not controlling the input fields through states. We are
manipulating the DOM by using Refs.
Higher Order Components in React
A component which takes a different component as a props and returns another
component
React Router
To install React Router type npm install react-router-dom
Setup Wrapper for React Router. i.e. Import {BrowserRouter} from “react-router-
dom”. Or
In the below Picture we have to import BrowserRouter,Route and Routes.
Always have to give path as /“YourComponent Name“
Use of Params in React Router
You can’t apply any class for CSS purpose in “Link” tag, instead of this you have to
use ”NavLink”. So if you are directly applying inline style then it will have the
utmost priority rather than any className
Pic-2
In the above picture-1 we have written the code how to use useSearchParams
hook. What is the use of it? – Its used to get the value from any
queryParams(QueryParams is the value which is shown in the URL section) shown
in the picture 2. I have used useQueryParams hook to get the value of city from
the query params. Here the city value is Noida and Age value is 10. So its showing
these values in the console.
If I want to set the QueryParams value into some user provide value then I can use
the setSearchParams hook.
We can also use both the QueryParams type in a single code. Here both the text
value and age value.
Navigation through Button Click
What is key – when we route from different location to another then all the routes
will have their unique key. Its not being used frequently and every time while
routing it will generate a new key.
What to modify and how to get different type of properties value –
To get the value of property ‘key’
How to use consumer, how to pass down the data into several children
How to change the color by clicking button
React Redux
Let you want to store some data like User Login or API data’s after refreshing a
page then we can use Redux there. It’s not a data base but kind of a big array
where you can store all data’s.
You can consider a Redux as stored container where you can store all your
Datas
You will get the whole data of the application inside the Store.
React sends the data of redux through props type only,like how we send data from
one component to another component through the props same like we will send
the data from one component to another by Redux which will be same as of props
sending
Redux architecture
Container - mapDispatchToProps -
mapStateToProps
When you will send the data from component to your Redux store to save then
you have to use mapDispactchToProps.
Now let the data which is stored inside the Redux Store need to be used anywhere
else / some third component then we can send the data from Store to any
component by mapStateToProps.
Have to import createStore from redux to create a store.
Have to import provider from react-redux to create a wrapper of provider in app.js
file.
How to share data’s between different component - redux-tut/src/components/Header.js at
master · anil-sidhu/redux-tut · GitHub
Learning from Project
How to install emmet -> emmet is used to complete your tags if you are typing
only class names -> ctrl+comma -> then search emmet -> Include Languages ->
javascript and javascriptreact -> Ctrl +P to relaod your vs code.
To install Material UI - npm install @mui/material or @material-ui/core
Display : flex; what it does It will make all the css components in a line like below
instead of one by one cloumn
To install VITE - npm create vite@latest. Have to rename all component files with
extension like .jsx instead of .js
For installing styling component - Npm Install styled-components
We can use <Themeprovider props={theme}> where theme is a function where we
have written our CSS code. We have used this tag to implement same CSS
properties in all the components
- Have to install laravel. 1 -laravel,2 -laravel new project_name
To run it - php artisan serve
- How to make a controller - php artisan make:controller UserController
Let GrandChild 2 needs a data from grandparent , so this will what happen next.
The Grand Parent component will pass the data to parent component then parent
component will pass the data to child component then child will pass the data to
Grandchild component. So in this way the parent and child get involved in a data
passing method where they did not want the data for them. This is what called as
Props drilling.
This is the fundamentals which is being used by Context API and Redux.