reactNotes
reactNotes
*React :
-it is javascript library.
-which is use to create rich user interface.
-It create single page application(SPA).
-Design and developed by facebook.
-latest version of React 18
*software pre-requisit
-nodejs
node -v
-npm
npm -v
-react
-editor
2.class component: when we have to implement and write complex logic in that case
we use it.
Note: while creating component in react its file name start with capital letter.
Task: create new react project and create one function component and display its
output.
==============================================
12/11/24
*class component
*How to create class component and get its output.
*What is JSX
-JSX(javascript and XML);
-it makes react code easy and allows us to write html code in react.
-in jsx we have put all element inside one parent element.
-the parent element must be block element.
*props :
-it is parameter or functional parameter which is use to pass data inside
component.
-it return object type of data.
-in function component we can access props by writting props.propsName.
-in class component we can access props by writting this.props.propsName.
Task1: you have to create one function component with name MyInfoComp and you have
to pass props with name fname,lname,contact,gender,address and display it output.
Task2: you have to create one class component with name MyFriendComp and you have
to pass props with name fname,lname,contact,gender,address and display it output.
*state :
-it is use to handle essesntial data in class component.
-state always write inside class constructor.
-it return object type of data.
-in class component we can access state property by writting
this.state.propertyName.
Task3: creter one class component having state property with name count and
increment ,decrement, and reset count value after clicking on three different
button.
*destructuring : creating constant variable to store data in it.
*destructuring of state
*destructuring of props
*Conditional Rendering:
-display component output on the basis of condition.
1. if else: in this if condition then if block block will display otherwise else
part will display.
4. short ciruit(&&): it is use of null checking , and it will display output only
when condition is true.
Task: create one component with name toggleImgCom in which you ahve to toggle two
images on click on single button
*Component Interaction :
-accessing data from parent component to child component, to perform this first we
have inbetween component they must have parent child relation.
ParentComp (cc)
-create state having empName, and salary propery and display it.
-implement logic after click on button empName and salary get change
*PureComponent:
-it is component provided by react ,
-which is use to prevent un-necesary re-rendering of class component,
-by performing shalow comparion.
-to achive this we extends component with PureComponent class
*React.memo():
-which is use to prevent un-necesary re-rendering of function component,
-by performing shalow comparion.
-to achive this we pass function component name as argument to React.memo() method.
===========================================================================
13/11/24
*VirtualDOM :
Task: Create class component with name EmpDataComp having state property with
employee containing array of object data for 10 employee with keyname
empId,empName,empPost,empSalary,empAddress,empGender and display data in table
formate.
step1 : install it
npm install react-bootstrap bootstrap
ste2: import its path in index.js file
MyCarousalComp (fc)
*use of snippet
rce : to create class component
rconst: it will create constructor,super method, state in class component.
rfce : it create react function component
rafce : it create react arrow function component
*ErrorBoundary :
-it is react component, which is use to handle error occure in component tree while
rendering component.
-it handle error which occure at the time component render.
-to achive this we use two class component lifecycle method
1.getDerivedStateFromError: this is static method, it will execute automatically
when error occure in child component.
2.componentDidcatch:it will error long or error information.
*Hooks In React
-it allows us to use class component feature in function component.
-by using react hooks we can use state in function component.
-react hooks introduce in reat version-16
*useState hook:
-it allows us to use state in function component.
-it return two values 1. currentState, 2.method-of-update-current-state
-useState hook accept all type of data (number,strinf,boolean,array,object)
-before using it import it first
src folder
Hooks folder
-UseStateHookComp (fc)
-UseEffectHookComp (fc)
Task: Create class component with name EmpDataComp having state property with
employee containing array of object data for 10 employee with keyname
empId,empName,empPost,empSalary,empAddress,empGender and display data in table
formate.
Task: display array data store in function component state and in unordered list
============================================================
14/11/24
*Routing in react:
-if you want to navigate from one component to another component for that we use
it.
-to perform routing in react we have to install react-router-dom library in react
project .
*types of routing
1. naming routing: to display component write component routing path in browser url
to get output of it.
2. default routing: when we have to display component output without writting its
routing path name in browser url.
4. child routing : when we have to display one routing inside another routing in
that case we use it.
-to perform child routing we use children property in routing object
-to display child component output in parent component for that we have add
<Outlet/> directory in parent component.
5. wild card routing: when user enter wrong routing path name in browser url in
that we redirect user to perticular component in that case we use it.
-for wild card routing in its path name we write * symbol
-ImpNote: wild card routing always write at last, its below routing will never
work.
component folder
FormvalComp (fc)
src folder
mainRouting folder
routing.js (file)
layout folder
LoginComp (fc)
NavComp (fc)
FooterComp (fc)
MainDashboardComp (fc)
PageNotFoundComp (fc)
*useEffect Hook:
-it is use to perform side effect in function component.
-side effect means , fetching data from server, use of timmer, DOM manipulation.
-useEffect hook execute after function component render.
-it return two values 1.callback function ,2.dependency
syntax: useEffect(()=>{},dependency)
src folder
CRUD folder
ProductDashComp (fc)
AddProductComp (fc)
EditProductComp (fc)
*Axios library:
-it is use to make request from react app to server
-it works on promisses concept
-how to install axios
npm i axios
cd src/shared/database
npx json-server --watch -p 8888 db.json
*Material UI:
-it is use to make react attractive and resposive.
-it provide inbuilt component.
-as well as it provide icon.
*how to access state and action from redux to react function component
-useSelector hook: it is use to access state from redux store to react
function component
-useDispatch Hook:it is use to call action from redux to react function
component.
localStorage.setItem("user1","Sham")
localStorage.getItem("user1");
localStorage.removeItem("user3");
localStorage.clear()
*Protected Routing