I trying to create a Dropdown that shows some list of an API depending on the number you selected on the dropdown.
For example, if in the dropdown if selected option 30 then it will show the list of 30 from 1-30. If I changed the option to 50 it will show 1-50. How can I do that?
The code :
const [data, setData] = useState([]);
const [id, setId]= useState('');
const [index, setIndex] = useState(10)
useEffect(() => {
const loadData = async () => {
await fetch(`https://swapi.dev/api/people/${id}/`)
.then((response) => response.json())
.then((ReceivedData) => setData(ReceivedData));
}
loadData()
},[id]);
return(
<select>
<option selected >10</option>
<option selected >50</option>
<option selected >60</option>
</select>
{data.map((datas,index){
<table className="table">
<tbody>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Height</th>
<th scope="col">Mass</th>
<th scope="col">Hair Color</th>
<th scope="col">Eye Color</th>
</tr>
</thead>
<tr key={index}>
<th scope="row">{datas.name}</th>
<td>{datas.height}</td>
<td>{datas.mass}</td>
<td>{datas.hair_color}</td>
<td>{datas.eye_color}</td>
</tr>
</tbody>
</table>)}
)