Помогите не работает функция fetch Суть: есть список карточек, по нажатию на одну из них…
- User
Помогите не работает функция fetch Суть: есть список карточек, по нажатию на одну из них надо перейти по ссылке к её описанию и подробной инфе. Я по сути не знаю как с помощью функции onClick передать uuid(id) в функцию handleClickGetNumber чтобы она отправила на сервак запрос с id-шником. Вот код:
export default function ImgMediaCard() {codeconst [uuid,setUUID] = React.useState('') const [number,setNumber] = React.useState('') const [numbers,setCards]=React.useState([]) const cardUUID = React.useState('')function handleClickGetNumber(uuid){
codeconst url = new URL('http://localhost:8080/cards/get/'); url.search = new URLSearchParams(uuid); fetch(url,{ method:"GET", headers:{"Content-Type":"application/json"}, // body:JSON.stringify(card) })}
codeReact.useEffect(()=>{ fetch("http://localhost:8080/cards/list") .then(res=>res.json()) .then((result)=>{ setCards(result);} )},[]) return ( <div > {numbers.map(card=>( <div className='Dives' key={card.number} style={{ display: 'inline-grid', maxWidth: "500px", maxHeight: "500px", paddingTop: "80px", // paddingRight: "100px", paddingLeft: "100px" }}> <CardMedia component="img" alt="DEFAULT" height="200" image={CarNumber} /> <Typography align='center' variant="body2" > </Typography> <CardActions> cardUUID = {card.uuid}; <Button size="small" onClick={handleClickGetNumber(cardUUID)}>Перейти к оформлению</Button> </CardActions> </div>))} </div> ); - Assistant