score:1

remove useeffect hook, the dependency for the hook is num and inside the callback of useeffect num is once again updated with setnum. this is a big no-no.

i suggest following changes to the handlechange callback

function handlechange(evt) {
    const value = evt.target.value;
    const inputelements = document
        .getelementbyid("app")
        .getelementsbytagname("input");
    let numberofinputelements = 1;
    if (numberofinputelements !== null) {
        numberofinputelements = inputelements.length - 1;
    }

    setnum((inputnum) => {
        for (const key in inputnum) {
            if (inputnum.hasownproperty(key)) {
                inputnum[key] = value / numberofinputelements;
            }
        }
        return { ...inputnum, [evt.target.name]: value };
    });
}

link to codesandbox for complete code.

but i understand your requirement is slightly different from the problem statement.


Related Query

More Query from same tag