# 如何强制更新一个Hooks组件

const [updater,setUpdater] = useState(0);;  //更新页面,重新渲染



const del = (e) => {
    // console.log(e.target.getAttribute("data-buildid"), "ccc");
    const buildId = e.target.getAttribute("data-buildid");
    let signature = getSingature(timestamp, nonce, accountcode, SignToken, '');

    let params = { buildId };
    let headers = { accountcode, timestamp, nonce, signature };
    const res = http.post(`/api/project/DeleteBuild?buildId=${buildId}`, null, headers);
    res.then((res) => {
        message.info(res.data.Data)
        setUpdater(updater => updater +1);  //需要更新的时候;
    });
};



  useEffect(() => {
    console.log(houseName,'effect11')
    axios({
      method: "get",
      url: "/api/account/GetToken",
      params: {
        accountCode: accountcode,
      },
      headers: { timestamp, nonce },
    })
      .then((res) => {
        sessionStorage.setItem("SignToken", res.data.Data.SignToken);
        const SignToken = res.data.Data.SignToken;
        let signature = getSingature(timestamp, nonce, accountcode, SignToken, "");
        axios({
          method: "get",
          url: "/api/project/GetBuildInfoByAccount",
          headers: {  accountcode,  timestamp, nonce,  signature},
        }).then((res) => {
          setAlldata(res.data.Data);
          // message.success(res.data.Data)
        });
      })
      .catch(function (error) {});
  }, [uploadStatus,houseName,updater]);  //---updater依赖更新
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
上次更新: 9/1/2022, 17:19:28