import React, { useState } from 'react'; const AddUser = () => { const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [message, setMessage] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); try { const response = await fetch('http://localhost:5001/add_user', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ name, email }), }); const data = await response.json(); if (response.ok) { setMessage(data.message); } else { setMessage(data.error); } } catch (error) { setMessage('An error occurred'); } }; return (
{message}
}