📌  相关文章
📜  强制组件重新渲染 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:25.744000             🧑  作者: Mango

代码示例2
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 */}
); }