Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub

一、变量解构一解就报错 优化前:

const App = (props) => {
  const { data } = props;
  const { name, age } = data
}

优化后:

const App = (props) => {
  const { data } = props;
  const { name, age } = data || {};
}

优化前

import React, { useState } from 'react';

const App = () => {
  const [loading, setLoading] = useState(false);
  const getData = async () => {
    setLoading(true);
    const res = await queryData();
    setLoading(false);
  }
}

优化后

import React, { useState } from 'react';
import to from 'await-to-js';

const App = () => {
  const [loading, setLoading] = useState(false);
  const getData = async () => {
    setLoading(true);
    const [err, res] = await to(queryData());
    setLoading(false);
  }
}

Edit this page
最近更新: 2025/12/2 01:46
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人