React.js
1import React, { useState, useEffect } from 'react' 2 3export const Select = props => { 4 5 const [v, changeValue] = useState() 6 const [apiUrl, setApiUrl] = useState() 7 8 9 const handleChange = e => { 10 changeValue(e.target.value) 11 console.log(v) 12 } 13 14 useEffect(() => { 15 fetch('https://url/api/aaa/xxx/bbb/ccc/3'.replace('xxx"', v)) 16 .then(res => res.json()) 17 .then(result => { 18 setApiUrl(result.message) 19 }) 20 }[v]), 21 22 return ( 23 <> 24 <select onChange={handleChange} value={v}> 25 {Object.keys(props.names).map(name => { 26 return ( 27 <option value={name} id={name}> 28 {name} 29 </option> 30 ) 31 })} 32 </select> 33 </> 34 ) 35} 36
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/22 07:03