body {
padding: 2rem 2rem 4rem;
}
ul {
display: block;
list-style-type: disc;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
padding-inline-start: 40px;
}
h2 {
display: block;
font-size: 1.17em;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
font-weight: bold;
}
h3 {
display: block;
font-size: 1em;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
font-weight: bold;
}
table {
margin-top: 1rem;
margin-bottom: 1rem;
}
table thead {
background-color: #f2f2f2;
text-align: left;
}
label {
display: block;
margin-right: 0.5rem;
}
select {
border-radius: 2px;
padding: 0.75rem 1rem;
-moz-appearance: none;
-webkit-appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
appearance: none;
background: transparent;
background-image: url("data:image/svg+xml;utf8,<svg fill='black' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
background-repeat: no-repeat;
background-position-x: 98%;
background-position-y: 12px;
border: 1px solid #ccc;
width: 320px;
}
option {
width: 100%;
border-radius: 10px;
padding: 1rem;
}
.box {
margin: 0rem auto 3rem auto
}
View Compiled
const { Component, CSSProperties, useEffect, useState, useCallback } = React;
const App = () => {
const [data1, setData1] = useState(null);
useEffect(() => {
const fetchData = async () => {
try {
const usersResponse = await fetch(
'https://jsonplaceholder.typicode.com/users'
)
const users = await usersResponse.json()
const usersWithPosts = await Promise.all(
users.map(async (user) => {
const postsResponse = await fetch(
`https://jsonplaceholder.typicode.com/posts?userId=${user.id}`
)
const posts = await postsResponse.json()
return { ...user, posts }
})
)
setData1(usersWithPosts)
} catch (error) {
console.error('Error fetching data:', error)
}
}
fetchData()
}, []);
return (
<div className="box">
<h1>Data from Endpoint 1:</h1>
<pre>{JSON.stringify(data1, null, 2)}</pre>
</div>
);
};
ReactDOM.render(<App />, document.getElementById("root"));
View Compiled