I am trying to build a dropdown from the data returned in API response. The API response looks like this:
{"departments": ["Admin","HR","IT","OPS","Accounts"]}
The retrieval is being in this manner. I need help in accessing the data in the form of a dropdown within <div>
function Dropdown() {
const [data, setData] = useState([{}])
useEffect(() => {
fetch("/listDepartments").then(
response => response.json()
).then(
data => {
setData(data)
console.log(data)
}
)
}, [])
return (
<div>
</div>
)
}
export default Dropdown;
1