3 글 보임 - 1 에서 3 까지 (총 3 중에서)
-
글쓴이글
-
2024년 5월 25일 01:23 #124038
박세헌참가자ai한테도 물어보고 영상도 여러번 다시보고 했지만 도저히 왜 작동 안하는지 모르겠네요ㅠㅠ 저한테만 안 보이는 걸까요? 혼자서 해보다가 분명히 돼야 한다고 생각하는데 자꾸 안돼서 강의영상 봤는데도 해결이 안되네요 몇개 조금 다른거 따라 고쳤는데도 계속 안되네요 Detail.jsx import React, { useEffect, useState } from 'react'; import '../Detail.css'; import { useParams } from 'react-router-dom'; import { pushObject } from '../store'; import Tab from './Tab'; import axios from 'axios'; import { useDispatch, useSelector } from 'react-redux';
export default function Detail({shoes, prdctLink}) {
useEffect(() => { setTimeout(() => { setFade('end'); }, 100); setFade('') },[])
const dispatch = useDispatch(); let [showResults, setShowResults] = useState(true); let [fade, setFade] = useState(''); const [Adata, SetAdata] = useState([]);
useEffect(() => { Promise.all([axios.get('https://codingapple1.github.io/shop/data2.json'),axios.get('https://codingapple1.github.io/shop/data3.json')]) .then((Data)=>{ let AdataFusion = [...shoes, ...Data[0].data, ...Data[1].data]; SetAdata(AdataFusion); }) .catch(()=>{ console.log('error') }) },[])
let {id} = useParams(); let findPrdct = Adata.find(function(x){ return x.id == id });
//console.log(findPrdct);
useEffect(function(){ setTimeout(function(){ setShowResults(false) }, 2000) }, [])
return ( <div className={'start ' + fade}> {showResults && <div className='saleBanner'> 2초 후에 사라지는 할인 배너</div>} { findPrdct && <section className='detailContainer'> < img src={findPrdct.src}/> <div className='content'> <h4>{findPrdct.title}</h4> <p className='text'>{findPrdct.content}</p> <p className='price'>{findPrdct.price}</p> <button className="btn" onClick={()=>{ dispatch(pushObject({ id: findPrdct.id, name: findPrdct.title, count: 1 })); }}>주문하기</button> </div> </section>} <Tab></Tab> </div> ); } Cart.jsx import React from 'react'; import { Table } from 'react-bootstrap'; import { useDispatch, useSelector } from 'react-redux'; import { changeCount } from '../store'; import Button from 'react-bootstrap/Button';
export default function Cart() {
let cartlist = useSelector(( state )=> state.cart) let dispatch = useDispatch()
return ( <div> <Table> <thead> <tr> <th>#</th> <th>상품명</th> <th>수량</th> <th>변경하기</th> </tr> </thead> <tbody> { cartlist.map((a, i) => { return ( <tr key={i}> <td>{cartlist[i].id}</td> <td>{cartlist[i].name}</td> <td>{cartlist[i].count}</td> <td><Button id={i} variant="secondary" onClick={()=> dispatch(changeCount(cartlist[i].id)) }>+</Button></td> </tr> ) }) } </tbody> </Table> </div> ); } store.js import { configureStore, createSlice } from '@reduxjs/toolkit'
let cart = createSlice({ name : 'cart', initialState : [ {id : 0, name : 'White and Black', count : 2}, {id : 2, name : 'Grey Yordan', count : 1} ], reducers : { changeCount(state, action){ let matchPrdct = state.find((x)=>{ return x.id == action.payload })
matchPrdct.count += 1 },
pushObject(state, action){ state.push(action.payload) } } })
export let { changeCount, pushObject } = cart.actions
export default configureStore({ reducer: { cart : cart.reducer, } })
-
이 게시글은
박세헌에 의해 1 년, 1 월 전에 수정됐습니다.
-
이 게시글은
-
글쓴이글
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
- 답변은 로그인 후 가능합니다.