React 学习笔记

2023-04-01  本文已影响0人  欢欣的膜笛

文档地址:https://react.dev/learn

react@18.2.0

Add React to a Website

transform JSX into HTML by add the Babel compiler

Built-in React Components

<Fragment> or <>...</>

<Profiler>

<Suspense>

<StrictMode>

Built-in React Hooks

useState(initialState)

useContext(SomeContext)

useReducer(reducer, initialArg, init?)

useRef(initialValue)

useCallback(fn, dependencies)

useMemo(calculateValue, dependencies)

useEffect(setup, dependencies?)

useLayoutEffect(setup, dependencies?)

useInsertionEffect(setup, dependencies?)

useDebugValue(value, format?)

useDeferredValue(value)

useId()

useImperativeHandle(ref, createHandle, dependencies?)

import { forwardRef } from 'react';

const MyInput = forwardRef(function MyInput(props, ref) {
  return <input {...props} ref={ref} />;
});
import { forwardRef, useImperativeHandle } from 'react';

const MyInput = forwardRef(function MyInput(props, ref) {
  useImperativeHandle(ref, () => {
    return {
      // ... your methods ...
    };
  }, []);

  return <input {...props} />;
});

useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot?)

useTransition()

Built-in React APIs

createContext

forwardRef

lazy

memo

startTransition

react-dom@18.2.0

React DOM APIs

createPortal

flushSync

Client React DOM APIs

createRoot

hydrateRoot

上一篇 下一篇

猜你喜欢

热点阅读