Hello I want to add a react component to the dom on button click. Here I have a simple function for it.
const addCargo = () => {
const parentElement = document.getElementById("addCargoContainer");
parentElement.insertBefore(<Cargo />, parentElement.children[2]);
}
but this gives me the following error:
Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node'.
Is there a possible way to do this?
const {cargos, setCargos} = useState([<Cargo />]) const addCargo = () => { setCargos([...cargos, <Cargo />]) }Well I tried this but doesnt seem to be working too