In React, do not use TypeScript to become AnyScript. The advantage is that it’s much easier to read, write, refactor, and maintain the second time around.

Types in real projects

  • It is best to abstract the types out and place them separately in types.ts, where each component has its own type file to hold various data types.

hooks

useState

  • Define the attempt value type
  • Define an attempt to reference type
  • Try to update asynchronously using async/await
  • Avoid large amounts of data
  • Paradigm constraints

useRef

  • Reference to the dom
  • Reference value
  • Reference unload prevents memory leaks
# references domconst Page: React.FC<any> = () = > {
    constdomRef = useRef<HTMLDivElement>(); # references domconst valueRef = useRef<boolean>(false); # reference the underlying type valueconstrefRef = useRef<boolean>({}); React.useEffect(() = > {
        return() {
            domRef.current = undefined; # offload DOM references to prevent memory leaks value.current =false; Refref. current = {} # refref. current = {} # Refref. current = {}Copy the code

useEffect

It deals specifically with side effects, there’s not much to talk about in terms of type.

Props

The type of props is the same as that of props.

Types in DVA

Types in ANTD