https://www.youtube.com/playlist?list=PL53HdtFIehli9YXokYdHDPj3voyXHYP8X
https://living-pull-611.notion.site/IEEE-React-Session-cb387e330b7545f98620518e1b37ecab
- ES7+ React/Redux/React-Native snippets
- ** Tailwind CSS IntelliSense
- React PropTypes Generate
- Prettier - Code formatter
- json-server doc
- tailwind cheat sheet
- React Router official Tutorial
- React Memo
- React useMemo
- React useCallback
- useReducer example
- useReducer Code
- custom hooks example useClipboard
- propTypes React
- Tools
- npm β πΉοΈ how to play with it?
- vite β replace
npx create-react app
- json-server β π donβt need Backend just fake it
- ** tailwind β just classnames π
- π΄ React Router β whereβs my pages??? π±
- π€ More Hooks
- ποΈ Hooks for more optimizations
Memo
β remember componentsuseMemo
β remember valuesuseCallback
β remember functions
- π€ Hooks for more control on your state
useState
β π comfort zoneuseReducer
β π΅βπ« Complex than everuseContext
β πΆ The grandchildrens should know.
- ποΈ Hooks for more optimizations
- π₯Έ More Advance Topics
Ref
β for DOM in react- Custom hooks β should make things easy !! should ********π¨
- Hocs (high order components) β wrap up the component π«
- Formik | YUP β handel forms like pro π¨βπ«
- Type Checking β Who I am ?? π
- Package.json
- Why?
- scripts
- dependencies
- devDependencies
command | what it do |
---|---|
npm init | initalize package.json |
npm i | alias for npm install β install all libraries in package.json |
npm i lib_name | install library lib_name package.json |
npm i -g lib_name | install library lib_name globally |
npm i -d lib_name | install library lib_name devDependencies |
npm un lib_name | uninstall library in package.json |
npm run script_name | run the command in scripts |
-
first letβs take look at the past β
-
What it Do Exactly?
- run your code locally
- bundle your files in single file for production
- more simple | fast + less errors
-
How To use it?
npm i -g vite
npm create vite@latest
npm run dev
-
npm install -g json-server
-
create dp.json with
{ "posts": [ {"id": 1,"heading": "hello world in js", "body": "console.log('hello')"} ], "tasks": [ {"body": "finish IEEE session", "isCompleted": false, "id": 1}, {"body": "Do A React project", "isCompleted": false, "id": 2} ] }
-
json-server --watch db.json
Method | Routes |
---|---|
GET-POST | http://localhost:3000/posts |
GET-PUT | PATCH |
GET | http://localhost:3000/tasks?body=finish%20IEEE%20session |
GET | http://localhost:3000/tasks?_page=1&_limit=2 |
etcβ¦. | there other functions [search, slice, sort, greater thanβ¦] β https://www.npmjs.com/package/json-server |
-
installation
-
npm install -D tailwindcss postcss autoprefixer
-
npx tailwindcss init -p
-
in tailwind.config.cjs
/** @type {import('tailwindcss').Config} */ module.exports = { content: [ "./index.html", "./src/**/*.{js,ts,jsx,tsx}", ], theme: { extend: {}, }, plugins: [], }
-
in index.css add this lines
@tailwind base; @tailwind components; @tailwind utilities;
-
-
Tailwind CSS IntelliSense =β vscode extension
-
cheat sheet β https://tailwindcomponents.com/cheatsheet/
Routes
graph TD
/ --> /posts
/ --> /tasks
/posts --> add
/posts --> :id
-
so how do i make multiple pages in React even itβs SAP
-
installation
npm install react-router-dom localforage match-sorter sort-by
import {createBrowserRouter, RouterProvider,} from "react-router-dom"; const router = createBrowserRouter([ { path: "/", element: <div>Hello world!</div>, }, ]); ReactDOM.createRoot(document.getElementById("root")).render( <React.StrictMode> <RouterProvider router={router} /> </React.StrictMode> );
-
error page
-
ErrorPage (component)
import { useRouteError } from "react-router-dom";
const error = useRouteError();
error.statusText || error.message
-
in router
errorElement: <ErrorPage />,
-
-
childreen
-
inside router
{ path: "/", element: <Root />, errorElement: <ErrorPage /> }, { path: "/posts", element: <Posts /> }
{ path: "/", element: <Root />, errorElement: <ErrorPage />, children: [ { path: "/posts", element: <Posts /> } ] },
-
Outlet [in parent component]
**import { Outlet } from "react-router-dom";**
**<Outlet />**
-
-
client side Routing [Link, NavLink]
<a href='/posts'>posts</a>
<NavLink to='/posts'>posts</NavLink>
<Link to='/posts'>posts</Link>
-
useParams()
**path: "/posts/:id",**
import { useParams } from 'react-router-domβ
const { id } = useParams();
Memo
β remember components β referenceuseMemo
β remember values β referenceuseCallback
β remember functions β reference
-
useState
β π comfort zone -
useReducer
β π΅βπ« Complex than ever-
Terms Reference 1 + Reference 2
- Life Example
- you will order from cashier
- cashier
- make new order with order details
- send order to kitchen system
- kitchen system add the new oder to current orders list
- when kitchen finish order β [the manager + cashier + you] should know
- Keywords
- store β Ψ§ΩΩ Ψ·ΨΉΩ ||||||||||||||| web form
- action have two things
- type β the new order
- payload β order details
- then the action dispatch in the kitchen and recived by some people called (reducers)
- reducers change state(Ψ§ΩΩΩΨ³ΨͺΨ©) ****of kitchen
- Life Example
-
-
useContext
β πΆ The grandchildrens should know.const CNTXT = createContext()
CNTXT.Provider value=ββ
const d = useContext()
npm install formik
npm install yup
import * as Yup from "yup";
export const signupInitialValues = {
username: "",
firstName: "",
lastName: "",
email: "",
password: "",
confirmPassword: "",
};
export const LoginSchema = Yup.object().shape({
/* email validation */
email: Yup.string().email("please enter a valid email").required("required"),
/* password validation */
password: Yup.string()
.min(8, "at least 8 characters")
.max(128, "at most 128 characters")
.minLowercase(1, "at lease 1 lower case letter")
.minUppercase(1, "at lease 1 upper case letter")
.minNumbers(1, "at least 1 number")
.minSymbols(1, "at lease 1 symbol")
.required("required"),
});
export const SignupSchema = LoginSchema.shape({
/* first name */
firstName: Yup.string()
.min(3, "at least 3 characters")
.max(32, "at most 32 characters")
.matches(/^[aA-zZ\s]+$/, "Only alphabets are allowed for this field ")
.required("required"),
lastName: Yup.string()
.min(3, "at least 3 characters")
.max(32, "at most 32 characters")
.matches(/^[aA-zZ\s]+$/, "Only alphabets are allowed for this field ")
.required("required"),
username: Yup.string()
.min(3, "at least 3 characters")
.max(32, "at most 32 characters")
.required("required"),
confirmPassword: Yup.string().oneOf(
[Yup.ref("password"), null],
"Passwords must match"
),
});
/////////////////////////
<Formik
initialValues={addArticleInitialValues(id)}
validationSchema={AddArticleSchema}
onSubmit={onSubmit}
>
<Form encType='multipart/form-data' className='form'>
npm install prop-types --save
import PropTypes from 'prop-types';
const Count = (props) => {
};
Count.propTypes = {
//// key is the name of the prop and
// value is the PropType
}