import { useEffect, useState } from "react"

export default function Test() {
  const [users, setUsers] = useState([])

  useEffect(() => {
    const loadUsers = async () => {
      try {
        const res = await fetch(
          "http://localhost/api/users.php"
        )

        const data = await res.json()

        setUsers(data)
      } catch (err) {
        console.error(err)
      }
    }

    loadUsers()
  }, [])

  return (
    <div>
      <h1>Users</h1>

      {users.map((user) => (
        <div key={user.id}>
          <p>{user.name}</p>
          <p>{user.email}</p>
          <p>{user.role}</p>
        </div>
      ))}
    </div>
  )
}