Reactjs 当我选择下拉列表时,如何点击api来显示分支? import React,{useState}来自“React”; 从“axios”导入axios; 常量应用=()=>{ const[value,setValue]=使用状态(“”); const[locations,setLocations]=useState([]); const handleSubmit=async()=>{ 如果(值==“”)返回; let response=等待axios.get(`https://api2-4ofagodxfq-uc.a.run.app/locality?stateName=KARNATAKA&districtName=BANGALORE&pinCode=${value}`); if(response.status==200)设置位置(response.data); } 返回 卡纳塔克邦 班加罗尔 PINCODE:setValue(e.target.value)}/> 提交 {locations.map((位置,索引)=>{ 返回{location} })} } 导出默认应用程序;

Reactjs 当我选择下拉列表时,如何点击api来显示分支? import React,{useState}来自“React”; 从“axios”导入axios; 常量应用=()=>{ const[value,setValue]=使用状态(“”); const[locations,setLocations]=useState([]); const handleSubmit=async()=>{ 如果(值==“”)返回; let response=等待axios.get(`https://api2-4ofagodxfq-uc.a.run.app/locality?stateName=KARNATAKA&districtName=BANGALORE&pinCode=${value}`); if(response.status==200)设置位置(response.data); } 返回 卡纳塔克邦 班加罗尔 PINCODE:setValue(e.target.value)}/> 提交 {locations.map((位置,索引)=>{ 返回{location} })} } 导出默认应用程序;,reactjs,axios,Reactjs,Axios,api在这里显示-尝试在selectonChange事件上调用api如何传递该值,我为select组件单击了dropdownwrite onChange事件 import React, { useState } from "react"; import axios from "axios"; const App = () => { const [value, setValue] = useState(''); const [locations, setLocations] = u

api在这里显示-

尝试在
select
onChange事件上调用api如何传递该值,我为select组件单击了dropdownwrite onChange事件
import React, { useState } from "react";
import axios from "axios";

const App = () => {
  const [value, setValue] = useState('');
  const [locations, setLocations] = useState([]);

  const handleSubmit = async () => {
    if (value === "") return;

    let response = await axios.get(`https://api2-4ofagodxfq-uc.a.run.app/locality?stateName=KARNATAKA&districtName=BANGALORE&pinCode=${value}`);
    if (response.status === 200) setLocations(response.data);
  }

  return <div>
    <select value="KARNATAKA">
      <option value="KARNATAKA">KARNATAKA</option>
    </select>
    <select value="BANGALORE">
      <option value="BANGALORE">BANGALORE</option>
    </select>
    PINCODE:<input type="text" onChange={e => setValue(e.target.value)} />
    <button type="button" onClick={handleSubmit}>SUBMIT</button>
    <select>
    {locations.map((location, index) => {
      return <option key={index}>{location}</option>
    })}
    </select>
  </div>
}

export default App;