select value from select and pass it to useeffect

Solutions on MaxInterview for select value from select and pass it to useeffect by the best coders in the world

showing results for - "select value from select and pass it to useeffect"
Nicole
10 Jan 2021
1const GetAPILinks = () => {
2  const [apiData, setApiData] = React.useState([]);
3  const [fetchUrl, setFetchUrl] = React.useState('');
4  React.useEffect(() => {
5    if (fetchUrl) {
6      fetch(fetchUrl)
7        .then((response) => {
8          return response.json();
9        })
10        .then((data) => {
11          setApiData(data);
12        });
13    }
14  }, [fetchUrl]);
15
16  return (
17    <DropdownButton id="dropdown-item-button" title="API Links" onSelect={(e)=>{setFetchUrl(e.target.eventKey)}}>
18        <Dropdown.Item as="button" eventKey='API_Link1'>Link 1</Dropdown.Item>
19        <Dropdown.Item as="button" eventKey='API_Link2'>Link 2</Dropdown.Item>
20        <Dropdown.Item as="button" eventKey='API_Link3'>Link 3</Dropdown.Item>
21    </DropdownButton>          
22  );
23}
24