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)
参考链接: