Limitation of JSX: need only one root element
need
wrapper => causing div soup
sol: use wrapper helper component work as empty component
use <React.Fragment>
use <> </>
React Portals (ReactDom.createPortal)
Modal should not be deeply nested => above root as sibling
Q. onClick vs onConfirm
Ref => mostly for reading element (ref.current)
controlled components: managed by react
uncontrolled: not managed by react
useReducer
Used for complect state management
const [state, dispatchFn] = useReducer(reducerFn, initialState, initFn);
React Context
Component-wide State Storage
ContextFn.Provider, ContextFn.Consumer
Most case, use props. But if data or function have to travel a lot of components (which even might not need the data nor function), use context
Authentication
is needed if content should be protected
Client(Browser) -> request to server with user credentials -> Server response with auth token
Authentication action was implemented to process login and logout mechanism
then send http request to communicate between server
07/17
Limitation of JSX: need only one root element need
<React.Fragment>
use<> </>
React Portals (ReactDom.createPortal) Modal should not be deeply nested => above root as sibling Q. onClick vs onConfirm
Ref => mostly for reading element (ref.current)
controlled components: managed by react uncontrolled: not managed by react
useReducer Used for complect state management
const [state, dispatchFn] = useReducer(reducerFn, initialState, initFn);
React Context Component-wide State Storage ContextFn.Provider, ContextFn.Consumer Most case, use props. But if data or function have to travel a lot of components (which even might not need the data nor function), use context
Authentication
07/18
Next.js
Pages Router
pages
directory is needed with index.js file because the name is reserved to NextJSpages/index.js
→/
pages/blog/index.js
→/blog
pages/posts/[dynamicVal].js
can be accessed withposts/1
,posts/2
useRouter().query.dynamicVal
to retrieve the param<Link href="/"></Link>
SPA navigationReturn pre-rendered page
getStaticProps()
is reserved code by Next.jsexport async function getStaticProps() {}
getServerSideProps()
is reserved code by Next.jsuseful when you need to serve up-to-date information that changes frequently
getStaticPaths is required for dynamic SSG pages when using
getStaticProps()
API Router
pages/api
directory is needed with index.js file because the name is reserved to NextJSAdding 'head'
import Head from "next/head";
07/19
Deployment
Deploying React Apps
Optimize Lazy loading
lazy import
() => import('./page/Blog').then((module) => module.loader())
Lazy fuction
lazy()
wherelazy(() => import('./pages/Blog'))
<Suspense>
Build App
npm run build
=> create build folderUpload
07/20
### React Animaion
CSS Animation
ReactTransitionGroup
npm install react-transition-group --save
https://reactcommunity.org/react-transition-group/Transition
<Transition>
component to show animationin={}
: conditiontimeout={}
: duration of the transitionmountOnEnter
andunmountOnExit
CSSTransition
appear
,enter
, andexit
states of the transition<CSSTransition classNames="my-css">
in CSS fileTransitionGroup
Alternative Animation Packages
React-Motion
,React-Move
,react-router-transition