📅  最后修改于: 2022-03-11 15:04:25.744000             🧑  作者: Mango
import React, { useState } from 'react';
//create your forceUpdate hook
function useForceUpdate(){
const [value, setValue] = useState(0); // integer state
return () => setValue(value => value + 1); // update the state to force render
}
function MyComponent() {
// call your hook here
const forceUpdate = useForceUpdate();
return (
{/*Clicking on the button will force to re-render like force update does */}
);
}