2
const [pergunta, setAddPergunta] = useState([])
async function pegarId(_id) {setAddPergunta(_id)
console.log(_id)}
<tbody>
{getPerg.map((pe, i) => (
<tr key={i}>
<th scope="row">{pe.area}</th>
<td
onClick={() => pegarId(pe._id)}
>
{pe.pergunta}<br></br>
<strong>Responder: </strong> <label> Sim </label> <input
value={false}
onChange={e => setResposta(e.target.value)}
type="radio"
/> <label> Não </label> <input
value={true}
onChange={e => setResposta(e.target.value)}
type="radio"
/>
</td>
</tr>
))}
</tbody>
What’s happening when I use the click
to catch the ID
of the question?
{
"pergunta":["5d6fa2fad1af7d3070ea7e8e"],
"_id":"5d71078671e10832c8e87e5d",
"responsavel":"Pedro",
"time":"5d6fe08e1814790dd084219a",
"createdAt":"2019-09-05T13:03:02.445Z","updatedAt":"2019-09-05T13:03:02.445Z",
"__v":0
}
What I wanted to happen was to save array
of a question in the bank.
{
"pergunta":'[
"5d6fa2fad1af7d3070ea7e8e",
"5d6fa86bd1af7d3070ea7e8f",
"5d6fa881d1af7d3070ea7e90"
]',
"_id":"5d71078671e10832c8e87e5d",
"responsavel":"Pedro",
"time":"5d6fe08e1814790dd084219a",
"createdAt":"2019-09-05T13:03:02.445Z","updatedAt":"2019-09-05T13:03:02.445Z",
"__v":0
}
Already use the method push
to add another array
and nothing like doing to catch the click
the IDS
and add inside the array
?
Ola pedro, only a suggestion, is worth taking a look at this publication of [meta], because your question of the way it was written is falling into one of the items covered in it, and this can make you be negativated - Manual on how NOT to ask questions =D
– Icaro Martins