React Hooks强制刷新

import React, { useReducer } from "react";
import ReactDOM from "react-dom";

import "./styles.css";

function App() {
  const [, forceUpdate] = useReducer(x => x + 1, 0);

  console.log("Rendered! or did I just re-render?");

  return (
    <div className="App">
      <button onClick={forceUpdate}>Force Update</button>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
    setTimeout(() => {
      forceUpdate()
    }, 0)

参考链接:

https://chat.xutongbao.top/

posted @ 2023-10-23 16:14  徐同保  阅读(23)  评论(0编辑  收藏  举报  来源