Open kurtzace opened 4 weeks ago
React test utils
pkellner/pluralsight-using-hooks-in-react18
Sapling to view React component tree
useEffect(() => { return () => {} }, [])
Basic Hooks useState, useEffect, useContext Additional Hooks useReducer, useCallback, useMemo, useRef, uselmperativeHandle, useLayoutEffect, useDebugValue, useDeferredValue, useTransition, useld Library Hooks useSyncExternalStore, uselnsertionEffect
const [state, dispatch] = useReducer (reducer, initialArg, init); reducer: A function that takes in 2 parameters, state and action and returns a new state. initialArg: The starting value of state. init: A function that returns the starting state
const imgRef = useRef();
return (
<div className="container">
<img src="/images/Speaker-1124.jpg"
ref={imgRef}
style={{ filter: "grayscale (100%)" }} onMouseOver={() => {
}}
imgRef.current.style.filter = "grayscale (0%)";|
/>
usecontext usage image
3rd party: redux, mobx, recoil
Remote: react query, swr, relay/Apollo
Webstore: local, session , index db
Local state
Lifted state
Derived : length of array
Refs : dom, uncontrolled components, non react libs , hold timer, track of component is mounted, store prev state value, undo ,redo
Url
React 18
course1
Concurrent features:
<Suspense fallback={<div>Loading...</div>}><div>UI...</div> </Suspense>
, lifecycle with useTransitionimport { useTransition, useState } from 'react'; function App() { } const [isPending, startTransition] = useTransition(); const [someState, setSomeState] = useState(); const someEvent = (event) => { } startTransition (() => { }); setSomeState(event.target.value); return <SlowComponent value={someState} />;