How do I use the information and pass it to the backend to retrieve something from the database?
code in site:
{Object.values(data)?.map((input) => (
<button
onClick={() => {
axios.get('/api/user', input).then(function (response) {
alert(response.reading);
});
}}
>
{input}
</button>
))}
code in node
import { db } from '../../lib/firebase';
export default async function handler(req, res) {
let store = {};
console.log(req.body, 'hello');
const user = await db.collection('readings').doc(req.body).get();
if (!user.exists) {
return res.status(404).json({});
}
return res.status(404).json({ id: user.id, ...user.data() });