Skip to content

GiaHuyyy/Hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hooks

import {

useState,
useEffect,
useLayoutEffect,
useRef,
useCallback,
useMemo,
useReducer,
userContext,
useImperativeHandle,
useDebugValue,
useDeferredValue
useId,
useOptimistic,
useInsertionEffect,
useTransition,
useSyncExternalStore

} from 'react'.

// Chưa sử dụng hooks, chỉ là UI component

function ComponentA() {

return <h1> Haven't used hooks yet </h1>

}

// Sử dụng hooks, hổ trợ thêm nhiều tính năng

function ComponentB() {

useState

const [state, setState] = useState(initState);

useEffect

useEffect(() => {

}, [deps])

useLayoutEffect(() => {

}, [deps])

useRef

const ref = useRef();

useCallback

const fn = useCallback(() => {

}, [deps])

useMemo

const results = useMemo(() => {

} , [deps])

useReducer

const [state, dispatch] = useReducer(reducer, initialArg, init)

useContext

const value = useContext(MyContext)

useImperativeHandle

useImperativeHandle(ref, createHandle, [deps])

useDebugValue

useDebugValue(isOnline ? 'isOnline': 'isOffline');

useDeferredValue

const deferredValue = useDeferredValue(value)

useId

const id = useId()

useOptimistic

const [optimisticState, addOptimistic] = useOptimistic(state, updateFn);

useInsertionEffect

seInsertionEffect(setup, dependencies?)

useTransition

const [isPending, startTransition] = useTransition()

useSyncExternalStore

const snapshot = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot?)

return <h1>Hooks</h1>

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published