For Programmer

11. 댓글 기능 생성(1) 구조 설명 - 유튜브 클론 코딩 본문

React & Node.js 프로젝트/유튜브 클론 코딩

11. 댓글 기능 생성(1) 구조 설명 - 유튜브 클론 코딩

유지광이 2020. 7. 26. 20:17
728x90

1.댓글구조

2.Comment model 생성(server-models-Comment.js)

const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const commentSchema = mongoose.Schema(
  {
    writer: {
      type: Schema.Types.ObjectId,
      ref: "User",
    },
    postId: {
      type: Schema.Types.ObjectId,
      ref: "Video",
    },
    responseTo: {
      type: Schema.Types.ObjectId,
      ref: "User",
    },
    content: {
      type: String,
    },
  },
  { timestamps: true }
);
const Comment = mongoose.model("Comment", commentSchema); //1st모델의이름,2nd데이터

module.exports = Comment; //다른파일에서사용가능

3.Comment Component 만들기(client-src-components-views-VideoDetailPage-Section-Comment.js)

import React from 'react';

function Comment() {
  return <div>Comment</div>;
}

export default Comment;

4.VideoDetailPage.js에서 import하기

import Comment from './Sections/Comment';
...생략
   title={VideoDetail.writer.name}
                description={VideoDetail.description}
              />
            </List.Item>
            {/* comment*/}
            <Comment /> //Comment import
          </div>
        </Col>
	... 이하 생략

해당강의

 

728x90
Comments