๐Ÿ”ฅ Today


  • mailjs ์‚ฌ์šฉํ•˜์—ฌ contact ํŽ˜์ด์ง€์— mail form ๊ธฐ๋Šฅ ๋งŒ๋“ค๊ธฐ
import { useInput } from "../hooks/useInput";
import { send } from "emailjs-com";

export const useId = process.env.REACT_APP_USER_ID;
export const templateId = process.env.REACT_APP_TEMPLATE_ID;
export const serviceID = process.env.REACT_APP_SERVICE_ID;

function MessageForm() {
  const [{ name, email, message }, onChange, reset] = useInput({
    name: "",
    email: "",
    message: "",
  });

  const onSubmit = (e) => {
    e.preventDefault();

    send(serviceID, templateId, { name, email, message }, useId)
      .then(() => {
        alert("๋ฉ”์ผ์ด ์ •์ƒ์ ์œผ๋กœ ์ „์†ก๋์Šต๋‹ˆ๋‹ค.๐Ÿš€");
      })
      .catch(() => {
        alert("๋ฉ”์ผ ์ „์†ก์„ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.๐Ÿ˜“");
      });

    reset();
  };

  return (
    <FormBox onSubmit={onSubmit}>
      <label htmlFor="name">Name</label>
      <input
        type="text"
        name="name"
        value={name}
        onChange={onChange}
        required
        placeholder="์„ฑํ•จ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
      />
      <label htmlFor="email">Mail</label>
      <input
        type="text"
        name="email"
        value={email}
        onChange={onChange}
        required
        placeholder="๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
      />
      <label htmlFor="message">Message</label>
      <MessageInput
        name="message"
        rows="10"
        value={message}
        onChange={onChange}
        required
        placeholder="๋‚ด์šฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
      ></MessageInput>
      <SendButton type="submit">๋ฉ”์ผ ๋ณด๋‚ด๊ธฐ</SendButton>
    </FormBox>
  );
}

export default React.memo(MessageForm);
  • useInput์€ ์ „์— ์‚ฌ์šฉํ•˜๋˜ hook์„ ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉํ–ˆ๋‹ค. ๋งค๋ฒˆ input์— ํ•„์š”ํ•œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์ง€ ์•Š์•„๋„ ๋ผ์„œ ์‹œ๊ฐ„๋„ ํ›จ์”ฌ ๋‹จ์ถ•๋˜๊ณ  ํŽธํ–ˆ๋‹ค.
  • serviceID์™€ templateId๋Š” ๊ณต๊ฐœ์ ? ์œผ๋กœ ๋…ธ์ถœ๋˜์–ด๋„ ์ƒ๊ด€์—†๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ, ๋‚˜๋Š” ๋”ฐ๋กœ env ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์„œ ๋ณด๊ด€ํ–ˆ๋‹ค.


๐Ÿ”ฅ To Do


  • [๋ถ€์ŠคํŠธ์ฝ”์Šค] project B
  • [Algorithm] javaScript ๋งค์ผ 1๋ฌธ์ œ ์ด์ƒ ํ’€๊ธฐ
  • [๋ถ€์ŠคํŠธ์ฝ”์Šค] CS ์ž๋ฃŒ๊ตฌ์กฐ, ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ฐ•์˜