React

[TIL/React] 2023/10/10

CartPage ์‹œ์ž‘ ๐ŸŸขdetail page์— ์žˆ๋Š” ๋‚ด์šฉ์ด๋‹ค. ๋ฐ”๋กœ๊ตฌ๋งค๋ฅผ ํด๋ฆญํ•˜๋ฉด ๊ฐ€์žฅ ๋จผ์ € if ๋ฌธ์„ ํ†ตํ•ด ๋กœ๊ทธ์ธ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•œ๋‹ค. ๋กœ๊ทธ์ธ์ด ๋˜์–ด ์žˆ์ง€ ์•Š์€ ์ƒํƒœ๋ผ๋ฉด ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๊ณ , ๋กœ๊ทธ์ธ์ด ์™„๋ฃŒ๋œ ์ƒํƒœ๋ผ๋ฉด ์‡ผํ•‘์นดํŠธ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•œ๋‹ค. ์ด๋•Œ ์ด๋™์— ์•ž์„œ

2023๋…„ 10์›” 10์ผ2min read

CartPage ์‹œ์ž‘ ๐ŸŸข

detail page์— ์žˆ๋Š” ๋‚ด์šฉ์ด๋‹ค. ๋ฐ”๋กœ๊ตฌ๋งค๋ฅผ ํด๋ฆญํ•˜๋ฉด ๊ฐ€์žฅ ๋จผ์ € if ๋ฌธ์„ ํ†ตํ•ด ๋กœ๊ทธ์ธ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•œ๋‹ค. ๋กœ๊ทธ์ธ์ด ๋˜์–ด ์žˆ์ง€ ์•Š์€ ์ƒํƒœ๋ผ๋ฉด ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๊ณ , ๋กœ๊ทธ์ธ์ด ์™„๋ฃŒ๋œ ์ƒํƒœ๋ผ๋ฉด ์‡ผํ•‘์นดํŠธ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•œ๋‹ค. ์ด๋•Œ ์ด๋™์— ์•ž์„œ dispatch๋ฅผ ํ†ตํ•ด DetailData์— category key๋ฅผ ์ถ”๊ฐ€ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ getCartData๋ผ๋Š” ์•ก์…˜ ํ•จ์ˆ˜๋กœ ์ „๋‹ฌํ•˜๊ฒŒ ๋œ๋‹ค.

CartPage ๐ŸŸข

์˜์—ญ์€ ํฌ๊ฒŒ ์„ธ ํŒŒํŠธ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. (์ œ๋ชฉ, ๋ฐ์ดํ„ฐ, ์ดํ•ฉ)์ด ๋ฐ”๋กœ ๊ทธ๊ฒƒ์ด๋‹ค. dataArea์™€ totalDataArea๊ฐ€ componentWrapper ๋‚ด๋ถ€์—์„œ 3๋Œ€ 1์˜ ๋น„์œจ๋กœ ์˜์—ญ์„ ์ฐจ์ง€ํ•˜๊ณ  ์žˆ๋‹ค.

dataArea๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌ์„ฑ๋œ๋‹ค.

์ƒํ’ˆ์ •๋ณด, ์ˆ˜๋Ÿ‰, ๊ฐ€๊ฒฉ์ด ๊ธฐ์žฌ๋œ ์ฒซ ๋ฒˆ์งธ ํ–‰์˜ ๋น„์œจ๊ณผ ๋™์ผํ•˜๊ฒŒ, ํ•˜๋‹จ์— ์ถ”๊ฐ€๋  ๋ฐ•์Šค์˜ ๋น„์œจ์„ ์กฐ์ •ํ•œ ๋ชจ์Šต์ด๋‹ค. ์„ธ ์˜์—ญ์—์„œ๋Š” useSelector๋ฅผ ํ†ตํ•ด ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ์ ์ ˆํžˆ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ๋‹ค.

์œ„ ์ฝ”๋“œ๋Š” ํ˜„์žฌ๋กœ์„œ ๊ฐ€์žฅ ๋ฌธ์ œ๊ฐ€ ๋งŽ์€ ๋ถ€๋ถ„์ด๋‹ค. ์ˆ˜๋Ÿ‰์— ๋”ฐ๋ฅธ ๊ฐ€๊ฒฉ์˜ ์ดํ•ฉ์„ ๋ณด์—ฌ์ค˜์•ผ ํ•œ๋‹ค.

code
import React, { useState } from "react";
import { useDispatch } from "react-redux";
import styled from "styled-components";
import { calElemTotalPrice } from "../../modules/cartSlice";
import { shoppingData } from "../../data/ShoppingCategory_Pork";
import { useLocation } from "react-router-dom";
import { useParams } from "react-router-dom";
import { splitPrice } from "../../utils/commonModule";

const CounterContainer = styled.div`
  display: flex;
  align-items: center;
`;

const Button = styled.button`
  padding: 10px 20px;
  font-size: 1.5em;
`;

const Display = styled.div`
  padding: 10px;
  font-size: 1.5em;
  margin: 0 20px;
`;

const Counter = () => {
  const [count, setCount] = useState(1);
  const { id } = useParams();
  const dispatch = useDispatch();
  const location = useLocation();
  const category = location?.state;
  const MapData = shoppingData[category];
  const DetailData = MapData?.find((elem) => elem?.id === id);
  const purePrice = splitPrice(DetailData?.price);

  const elemTotalPrice = purePrice * (count + 1);

  const updateCount = (st) => {
    dispatch(calElemTotalPrice(st));
  };

  const handleIncrement = () => {
    setCount((prevCount) => prevCount + 1);
  };

  const handleDecrement = () => {
    if (count > 1) {
      setCount((prevCount) => prevCount - 1);
    }
  };

  return (
    <CounterContainer>
      <Button
        onClick={() => {
          updateCount(elemTotalPrice);
          handleDecrement();
        }}
      >
        -
      </Button>
      <Display>{count}</Display>
      <Button
        onClick={() => {
          updateCount(elemTotalPrice);
          handleIncrement();
        }}
      >
        +
      </Button>
    </CounterContainer>
  );
};

export default Counter;

์š”์†Œ์˜ total price๋ฅผ ๊ตฌํ•ด์„œ updateCount๋ผ๋Š” ์•ก์…˜ ํ•จ์ˆ˜์— ์ „๋‹ฌํ•˜๊ณ , ํ•ด๋‹น ๊ฐ’์œผ๋กœ ์ƒํƒœ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•œ๋‹ค๋Š” ๋…ผ๋ฆฌ์ด๋‹ค. ๋ฌธ์ œ๋Š” category๋ณ„๋กœ ์ ‘๊ทผํ•˜์ง€ ์•Š์•„์„œ ๋‚˜๋จธ์ง€ ์š”์†Œ๋“ค์˜ ๊ฐ€๊ฒฉ์ด ๋™์ผํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚œ๋‹ค. ๋ฌด์Šจ ๋ง์ผ๊นŒ?

๊ทธ์ € ์—‰๋ง์ด๋ผ๋Š” ์†Œ๋ฆฌ๋‹ค. ๋‚ด์ผ์€ ์ด ๋ถ€๋ถ„๋ถ€ํ„ฐ ํ•ด๊ฒฐํ•˜๊ฒ ๋‹ค.

More to read

AI

AI&ML ๊ธฐ์ดˆ

Reference: https&#x3A;//bettermesol.github.io/ml/2019/09/16/ai-ml-dl/AI: ๊ธฐ๊ณ„๊ฐ€ ์‚ฌ๋žŒ์ฒ˜๋Ÿผ ์ƒ๊ฐํ•˜๊ณ  ํŒ๋‹จํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ๊ฐ€์žฅ ๋„“์€ ๋ฒ”์ฃผ์˜ ๊ธฐ์ˆ ์ž…๋‹ˆ๋‹ค.ML: ๋ฐ์ดํ„ฐ๋ฅผ ํ•™์Šตํ•˜์—ฌ ์Šค์Šค๋กœ ๊ทœ์น™์„ ์ฐพ์•„๋‚ด๋Š” AI์˜ ํ•œ ๋ถ„์•ผ๋กœ,

'AI Agent Economy'

Novitas : AI Agent๊ฐ€ ์ง€๊ฐ‘์„ ๊ฐ€์ง€๋Š” ์„ธ์ƒ

์–ผ๋งˆ ์ „, ๋ฏธ๋ž˜์—์…‹์ฆ๊ถŒ ๋ฆฌ์„œ์น˜ ๋ฆฌํฌํŠธ(์˜ฌํ•ด๋Š” ์ด๋”๋ฆฌ์›€์ด๋‹ค: ์—์ด์ „ํŠธ ์‹œ๋Œ€์˜ Near Automata)๋ฅผ ์ ‘ํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. AI Agent๋ฅผ ์ธ๊ฐ„๊ณผ ํ•จ๊ป˜ํ•  ๊ฒฝ์ œ ์ฃผ์ฒด๋กœ ๋ฐ”๋ผ๋ณด๋Š” ์‹œ๊ฐ์— ์ ์ž–์ด ์ถฉ๊ฒฉ์„ ๋ฐ›์•˜๋”๋žฌ์ฃ .ํ•œ ๊ฐ€์ง€ ์งš๊ณ  ๋„˜์–ด๊ฐˆ ๋ถ€๋ถ„์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ํ”ํžˆ 'AI'

'ERC-8004'

Novitas: AI ์—์ด์ „ํŠธ ๊ฒฝ์ œ ์ฃผ์ฒด

Web 4.0์„ ํ•œ ๋ฌธ์žฅ์œผ๋กœ ์ •์˜ํ•˜๋ฉด Sovereign Transact์ž…๋‹ˆ๋‹ค.AI๊ฐ€ ์ธ๊ฐ„์˜ ํ—ˆ๋ฝ ์—†์ด ์ง€๊ฐ‘์„ ์†Œ์œ ํ•˜๊ณ , ๊ฒฐ์ œ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉฐ, ์ธํ”„๋ผ๋ฅผ ํ†ต์ œํ•˜๋Š” ์ฃผ๊ถŒ์  ๊ฒฝ์ œ ์ฃผ์ฒด๊ฐ€ ๋˜๋Š” ์„ธ๊ณ„์ž…๋‹ˆ๋‹ค. Web 3.0์ด ๋ธ”๋ก์ฒด์ธ ๊ธฐ๋ฐ˜์˜ ํƒˆ์ค‘์•™ํ™”๋ฅผ ์‹คํ˜„ํ–ˆ๋‹ค๋ฉด, Web 4.0์€ ๊ทธ