ДЗ6. Переписать проект на React#4
Conversation
| const [products, setProsucts] = useState(); | ||
|
|
||
| useEffect(() => { | ||
| axios.get('http://localhost:3006/item').then(resp => { |
There was a problem hiding this comment.
давай немного настроим axios, сделаем отделный объект в котором уже будет зашит общий url
There was a problem hiding this comment.
создадим папку src/api и там index.js (по идее более правильно будет резделить в папке на отделный файлы, но не будем усложнять) и там уже отдельно сделаем методы получения данных
There was a problem hiding this comment.
т. е. здесь будет вызываться метод getItems()
| }; | ||
|
|
||
| return ( | ||
| <> |
| } | ||
|
|
||
| return ( | ||
| <> |
| const [info, setInfo] = useState(); | ||
|
|
||
| useEffect(() => { | ||
| axios.get('http://localhost:3006/item/:itemId').then(resp => { |
There was a problem hiding this comment.
вместо :itemId, т. е. с условием того что методы получения данных вынесем в отдельные папки, здесь будет что-то типа
getItem(id)
| const product = props.product; | ||
|
|
||
| return ( | ||
| <> |
| <Header /> | ||
| <Routes> | ||
| <Route path='/' exact element={<Catalog />} /> | ||
| <Route path='/info-product' exact element={<ProductInfo />} /> |
There was a problem hiding this comment.
давай сделаем здесь
path='/info-product/:id'
чтоб как по правде было, а в компоненте карточки в каталоге будем переходит по роуту с соответствующим id
|
|
||
| if (!products || products.lenght === 0) { | ||
| return ( | ||
| <> |
| }; | ||
|
|
||
| return ( | ||
| <> |
| }; | ||
|
|
||
| return ( | ||
| <> |
|
|
||
| return ( | ||
| <> | ||
| <CardWrapper to='/info-product'> |
There was a problem hiding this comment.
давай здесь сделаем переход с указанием id
No description provided.