I have a table that gathers user input from two selects. When the user selects a field, i have successfully made it so that their input is shown on a table row, and any new input triggers a new row.
However I am having great difficulty in making it so that it displays multiple values instead of one. This is what it currently looks like:
Where it says the input example 'P2P2' it should only say 'P2'; everytime a new row is added the 'P2' is successfully added but it always builds up on top of each other unlike the 'Amazon' input like this:
I know i am doing something wrong and have tried multiple methods but I dont actually know what the issue is or how to resolve the issue. Here is the code:
const [shop, setShop] = useState([]);
const [profil, setProfil] = useState([]);
const [formShop, setFormShop] = useState(undefined);
const [formProfil, setFormProfil] = useState(undefined);
function addShop(s){
setShop((currentShops) => [...currentShops, s]);
}
function addProfile(p){
setProfil((currentProfiles) => [...currentProfiles, p]);
}
function handleSubmit(e){
e.preventDefault();
addShop(formShop);
addProfile(formProfil);
}
......
<tr>
{(shop.map((s) => (
<tr>
<td>{s}</td>
<td>{profil}</td>
</tr>
)))}
</tr>
........
//snippets of form select
<Input type="select" name="selectStore" id="selectStore" onChange={(e) => setFormShop(e.target.value)}>
........
<Input type="select" name="selectProf" id="selectProf" onChange={(e) => setFormProfil(e.target.value)}>
........