묻고 답해요
161만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결한 입 크기로 잘라 먹는 리액트(React.js) : 기초부터 실전까지
React Hook useMemo has a missing dependency
강사님 강사님의 강의를 들으며 진행하고 있는데 아래와 같은 경고 메시지가 계속 나와 경고 메시지를 받지 않으려면 어떻게 코드를 작성해야 하는지 궁금해서 질문 드립니다!아래는 제가 작성한 코드입니다https://codesandbox.io/s/youthful-glitter-6thymf?file=/src/App.js:0-2523Line 54:8: React Hook useMemo has a missing dependency: 'data'. Either include it or remove the dependency array react-hooks/exhaustive-deps Line 58:51: React Hook useMemo has missing dependencies: 'addDiary', 'deleteDiary', and 'editDiary'. Either include them or remove the dependency array react-hooks/exhaustive-deps
-
미해결따라하며 배우는 리액트 테스트 [2023.11 업데이트]
Test Fail이 발생합니다 ㅠㅠ
현재 섹션5까지 수강 완료한 상태인데 계속 Fail이 발생합니다 ㅠㅠ처음엔 됐었는데 갑자기 안되더라구영 ㅠㅠ 검색을 해봐도 뭐가 문제인지 파악하기 힘들어서 질문 드립니다!어떻게 해결하면 좋을까요?
-
미해결따라하며 배우는 노드, 리액트 시리즈 - 레딧 사이트 만들기(NextJS)(Pages Router)
배포하고 나서는 visual studio code에서는 실행못하나요?
- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요! - 먼저 유사한 질문이 있었는지 검색해보세요. - 서로 예의를 지키며 존중하는 문화를 만들어가요. - 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요. AWS로 배포하고나면 visual studio code에서 npm으로 로컬실행을 할 수 없을 까여?
-
해결됨Slack 클론 코딩[실시간 채팅 with React]
proxy, cors 관련해서 질문있습니다! (오류 사항은 아닙니다!)
안녕하세요. 혼자 개인 프로젝트를 하면서 강의를 듣고 있는데 궁금한 점이 생겨서 질문 남깁니다! 현재 projectA 안에 프론트, 백 폴더를 제로초님처럼 만들어놓고 프론트는 react+typescript / 백은 nestjs+typescript 로 전부 설치해놓은 상태입니다.다만, 이렇게 할 경우 proxy 설정을 프론트에서 해줘야 된다고 하여 아래 처럼 설정을 해당 강의 듣기전에 구글링하여 만들어놨었습니다. 미들웨어 설치 npm i http-proxy-middlewareprojectA > pront > src > setupProxy.tsconst { createProxyMiddleware } = require("http-proxy-middleware"); module.exports = function (app) { app.use( createProxyMiddleware("/api", { target: "http://localhost:3095", changeOrigin: true, }) ); }; package.json// 위에 생략... "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "proxy": "http://localhost:3095/", // 아래 생략... 여기서 궁금한 점이.. proxy를 설정할 때 미들웨어를 설치하여 setupProxy.js 파일을 만들어서 사용하라는 글들을 많이 봐서 그대로 따라하고 파일명만 ts로 변경했었습니다. 이렇게 하니 api를 불러오는 url 부분에 localhost:3095~~~ 이 부분을 전부 다 입력해야 에러가 나지 않았고 생략해서 사용하려면 package.json에 proxy 경로를 추가하는 방법밖에는 없는걸까요??(미들웨어 설치 + setupProxy.ts 파일로만 proxy 설정을 해보고 싶었는데 이 경우에는 api url 불러오는 부분에 locallhost~~~... 를 쓸 수 밖에 없는지가 궁금합니다.) 다만.. package.json에 proxy 경로를 넣어놓고 setupProxy.ts 파일의 코드를 지워도 제대로 돌아가더라구요.. setupProxy.ts 파일을 잘 못 만든걸까요? 이때 돌아가는 이유가 package.json의 proxy 경로로만 인식을 한 것 같습니다..https://www.npmjs.com/package/http-proxy-middleware 마지막으로 위 proxy 설정 파일을 해주면 cors 오류가 발생하지 않는 것 같은데 둘중 하나만 설정을 해주는 것이 맞을까요? 둘다 해줘야 하는건지.. 프론트에서 proxy만 하거나 백에서 cors를 설치하는 방향 둘중에 뭐가 더 나은 방향인지도 궁금합니다!원래는 아래 cors 설치하고 아래 코드까지 작성 해놨었습니다.main.ts(back 폴더안)import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import cors = require('cors'); async function bootstrap() { const app = await NestFactory.create(AppModule); app.use(cors()); await app.listen(process.env.PORT); console.log(`listening on port ${process.env.PORT}`); } bootstrap();
-
미해결처음 만난 리액트(React)
미니 블로그 질문입니다.
미니블로그를 실행시키면 아래와 같은 에러가 브라우저 콘솔에 찍힙니다.소스는 몇 번을 확인해서 잘 못 된 부분이 없다고 생각합니다.MainPage.jsx 부터 불러오질 못하네요.뭐가 잘 못 됐는지 찾아주시면 고맙겠습니다.아래는 App.js 에 PostWritePage, PostViewPage 를 빼고 실행했을 경우 브라우저 페이지 자체에 나오는 에러입니다. function App(props) { return ( <BrowserRouter> <MainTitleText>제플리카의 미니 블로그</MainTitleText> <Routes> <Route index element={<MainPage />} /> </Routes> </BrowserRouter> ); } Uncaught runtime errors:×ERRORElement type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of MainPage. Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of MainPage. at createFiberFromTypeAndProps (http://localhost:3000/static/js/bundle.js:36883:21) at createFiberFromElement (http://localhost:3000/static/js/bundle.js:36904:19) at createChild (http://localhost:3000/static/js/bundle.js:25473:32) at reconcileChildrenArray (http://localhost:3000/static/js/bundle.js:25713:29) at reconcileChildFibers (http://localhost:3000/static/js/bundle.js:26055:20) at reconcileChildren (http://localhost:3000/static/js/bundle.js:28987:32) at updateHostComponent (http://localhost:3000/static/js/bundle.js:29631:7) at beginWork (http://localhost:3000/static/js/bundle.js:31076:18) at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:16062:18) at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:16106:20)ERRORElement type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of MainPage. Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of MainPage. at createFiberFromTypeAndProps (http://localhost:3000/static/js/bundle.js:36883:21) at createFiberFromElement (http://localhost:3000/static/js/bundle.js:36904:19) at createChild (http://localhost:3000/static/js/bundle.js:25473:32) at reconcileChildrenArray (http://localhost:3000/static/js/bundle.js:25713:29) at reconcileChildFibers (http://localhost:3000/static/js/bundle.js:26055:20) at reconcileChildren (http://localhost:3000/static/js/bundle.js:28987:32) at updateHostComponent (http://localhost:3000/static/js/bundle.js:29631:7) at beginWork (http://localhost:3000/static/js/bundle.js:31076:18) at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:16062:18) at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:16106:20)ERRORElement type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of MainPage. Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of MainPage. at createFiberFromTypeAndProps (http://localhost:3000/static/js/bundle.js:36883:21) at createFiberFromElement (http://localhost:3000/static/js/bundle.js:36904:19) at createChild (http://localhost:3000/static/js/bundle.js:25473:32) at reconcileChildrenArray (http://localhost:3000/static/js/bundle.js:25713:29) at reconcileChildFibers (http://localhost:3000/static/js/bundle.js:26055:20) at reconcileChildren (http://localhost:3000/static/js/bundle.js:28987:32) at updateHostComponent (http://localhost:3000/static/js/bundle.js:29631:7) at beginWork (http://localhost:3000/static/js/bundle.js:31076:18) at beginWork$1 (http://localhost:3000/static/js/bundle.js:36015:18) at performUnitOfWork (http://localhost:3000/static/js/bundle.js:35284:16)
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 프론트엔드 코스
<코멘트달기 section> boardId 오류
import { useState } from "react"; import CommentPageUi from "./BoardCommentWrite.presenter"; import { useMutation } from "@apollo/client"; import { CREATE_BOARD_COMMENT } from "./BoardCommentWrite.queries"; import { useRouter } from "next/router"; import { FETCH_BOARD_COMMENTS } from "../list/BoardCommentList.queries"; export default function CommentPage () { const [writer, setWriter] = useState(""); const [password, setPassword] = useState(""); const [contents, setContents] = useState(""); const [createBoardComment] = useMutation(CREATE_BOARD_COMMENT) const router = useRouter; const onChangeWriter = (event) => { setWriter(event.target.value) } const onChangePassword = (event) => { setPassword(event.target.value) } const onChangeContents = (event) => { setContents(event.target.value) } const onClickSubmit =async() => { try { await createBoardComment ({ variables : { createBoardCommentInput: { writer : writer, password : password, contents : contents, rating: 0, }, boardId: router.query.boardId, }, refetchQueries: [ { query: FETCH_BOARD_COMMENTS, variables: { boardId : router.query.boardId}, }, ], }); } catch (error) { alert(error.message); } alert("정상적으로 댓글이 달렸습니다.") } return ( <CommentPageUi onChangeWriter = {onChangeWriter} onChangePassword ={onChangePassword} onChangeContents ={onChangeContents} onClickSubmit = {onClickSubmit} contents={contents} > </CommentPageUi> ) }comment write import { gql } from "@apollo/client"; export const CREATE_BOARD_COMMENT = gql` mutation createBoardComment( $createBoardCommentInput: CreateBoardCommentInput! $boardId: ID! ) { createBoardComment( createBoardCommentInput: $createBoardCommentInput boardId: $boardId ) { _id } } `;comment write queryimport { gql } from "@apollo/client"; export const FETCH_BOARD_COMMENTS = gql` query fetchBoardComments($boardId: ID!) { fetchBoardComments(boardId: $boardId) { _id writer contents createdAt rating } } `;comment list queryimport { useQuery } from "@apollo/client" import { FETCH_BOARD_COMMENTS } from "./BoardCommentList.queries" import { useRouter } from "next/router" import BoardCommentListUI from "./BoardCommentList.presenter" export default function BoardCommentList() { const router = useRouter() const {data} = useQuery(FETCH_BOARD_COMMENTS, { variables: {boardId : router.query.boardId} }) return ( <BoardCommentListUI data={data} /> ) }comment list폴더명 에러1에러2둘 다 boardId와 관련있고, 내용으로 봐서는 boardId에 값이 없는 것 같은데, 코드를 아무리 봐도 문제점을 모르겠네요.. 문제가 뭘까요 ???
-
미해결Slack 클론 코딩[실시간 채팅 with React]
프론트,백엔드도 https적용되었는데 morgan에는 HTTP통신으로 나옵니다. 쿠키 적용이안됩니다.
백엔드를 npm run start로 했을 시 로그인이 안되는 문제가 있습니다.프론트,백엔드 https적용되어있고 같은 도메인을 쓰고있습니다.app.js에 cookie.secure를 주석처리하면 로그인이 됩니다.질문드린 이유는 지금 제 프론트 <-> 백엔드가 https 통신이 아닌 것인지맞다면 왜 cookie.secure를 true로 했을 때 왜 쿠키가 설정이 안되는 것인지 알고싶습니다. -시도한 방법 -domain에 상위도메인 넣어보았는데도 안됩니다 ㅠ저와 비슷한 상황을 겪은 분의 질문을 보던 중 궁금한 게 있어서 이것도 적어봅니다.https://www.inflearn.com/questions/342672/express-aws-%EB%B0%B0%ED%8F%AC-%ED%9B%84-%EC%84%B8%EC%85%98-%EC%BF%A0%ED%82%A4여기서 cors는 어떻게 하란걸까요? -아래는 제 상황을 파악하시는데 도움이 될만한 내용을 적어봤습니다.- 아래는 프론트에서 login 요청시 morgan 로그입니다.프론트 url입니다 => https가 적용되어있습니다.아래는 백엔드 url을 인터넷주소창에 쳤을 때입니다.아래는 프론트에서 백엔드로 login 요청했을 때 요청헤더입니다. 아래는 백엔드서버 nginx 설정입니다.Route53 호스팅 영역 설정입니다.app으로 시작하는게 백엔드입니다. (CNAME이런건 그림판으로 지웠습니다.)가비아에도 서브도메인으로 등록했습니다.
-
해결됨[리뉴얼] React로 NodeBird SNS 만들기
posts.js 라우터 파일에 문제가 생겼습니다
const express = require('express'); const { User, Post, Image, Comment } = require('../models'); const router = express.Router(); console.log(Post); // undefined router.get('/', async (req, res, next) => { try { const posts = await Post.findAll({ limit: 10, order: [ ['createdAt', 'DESC'], [Comment, 'createdAt', 'DESC'], ], include: [{ model: User, attributes: ['id', 'nickname'], }, { model: Image, }, { model: Comment, include: [{ model: User, attributes: ['id', 'nickname'], }], }, { model: User, as: 'Likers', attributes: ['id'], }], }); res.status(200).json(posts); } catch (error) { console.error(error); next(error); } }); module.exports = router;posts.jsconst express = require('express'); const cors = require('cors'); const passport = require('passport'); const session = require('express-session'); const cookieParser = require('cookie-parser'); const dotenv = require('dotenv'); const morgan = require('morgan'); const db = require('./models'); const passportConfig = require('./passport'); const postRouter = require('./routes/post'); const userRouter = require('./routes/user'); const postsRouter = require('./routes/posts'); dotenv.config(); db.sequelize.sync() .then(() => { console.log('db 연결 성공'); }) .catch(console.error); passportConfig(); const app = express(); app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(cors({ origin: true, credentials: true, })); app.use(cookieParser(process.env.COOKIE_SECRET)); app.use(session({ saveUninitialized: false, resave: false, secret: process.env.COOKIE_SECRET, })); app.use(passport.initialize()); app.use(passport.session()); app.use(morgan('dev')); app.use('/posts', postsRouter); app.use('/post', postRouter); app.use('/user', userRouter); app.listen(3065, () => { console.log('3065포트 서버실행중'); });app.js(node:4192) Warning: Accessing non-existent property 'User' of module exports inside circular dependency (node:4192) Warning: Accessing non-existent property 'Post' of module exports inside circular dependency // 생략영상보면서 코딩중에위 문구와 함께 ../models에서 require한 것이존재하지 않는 문제가 발생했습니다.const { Post } = require('../models')console.log(Post) 출력결과 undefined 입니다이 문제가 posts.js 파일에서만 발생했습니다.(user.js, post.js는 정상)그래서 postss.js 라는 이름이 다르고 코드만 옮긴 파일을 만들어서 다시 시도해보았습니다.(rename시 module not found 에러 발생)그랬더니 ../models에서 require 한것이 존재했습니다.근데 요청시라우터(method: get, url: /posts)의 미들웨어가 실행이 안되는 문제가 있었습니다.상태코드는 300 Multiple Choices 였습니다이번에는 url를 바꿔서 요청을 보냈습니다ex) /posts/test그랬더니 성공했습니다.왜 이런 현상이 발생했는지어떻게 해결할 수 있는지 모르겠어서 질문남깁니다!
-
미해결비전공자를 위한 진짜 입문 올인원 개발 부트캠프
node server.js 실행 시 오류 발생
Express에서 데이터 처리하기 강의 수강 중에 생긴 오류 입니다. 이후에 포스트맨에서 body 수정 후 send 시에도 Error: connect ECONNREFUSED이 오류가 떳습니다.index.js를 실행 후에 웹 브라우저에 http://localhost:8080/products 입력하면 [{"name":"농구공","price":5000}] 이렇게 웹 화면에 뜨면서 node:events:492 thorw er;도 같이 뜨면서 서버 에러가 납니다 database.sqlite3을 vs코드 열었을 때는 위 사진처럼 뜨고sqllite로 열었을 때는 읽을 수 없다고 뜹니다
-
해결됨Slack 클론 코딩[실시간 채팅 with React]
회원가입할 때 POST요청에 대한 응답이 500에러가 뜹니다.
다른 질문글들을 살펴보니 .env파일 설정이 안되어 있거나 back 서버를 구동하지 않은 상태에서 에러가 나던데 저는 .env파일과 back서버 모두 구동을 했음에도 에러가 뜹니다. 제가 했던 설정 중 일반적인 설정과 다른 경우는 1장에서 db를 생성하고 만들었을 때 mysql비밀번호가 있음에도 도저히 인식하지 못해 설정파일에 변수명이 아닌 직접 비밀번호를 입력한 경우를 제외하곤 강의에서 설명한 설정 그대로 수행했습니다. 어떤게 문제일까요?
-
미해결웹 게임을 만들며 배우는 React
소스관련해서
소스와 코드 요소를 작성할 때 위치 잡는 방법 팁 같은게 있나요?
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 프론트엔드 코스
수정하기 뮤테이션
안녕하세요 선생님 !하나 궁금한 점이 있어서 질문 드려요.게시물 수정할 때, 기존에 입력한 값이 사라지고 수정한 내용만 남는 문제가 발생해, 수정하기 버튼을 눌렀을 때 기존 값도 남아있고, 수정한 내용도 체인지 돼서 나오게끔 하는 부분을 공부중입니다.(이미지는 강의내용 캡쳐입니다)궁금한 게, 이렇게 코드를 적용하고 게시물을 수정하면 바뀐 내용들만 뮤테이션이 날라간다는 건 이해 하겠는데 기존에 입력한 값들이 안 사라지고 출력되는 건 이해가 쉽지 않네요.. !! 어차피 writer,title,contents 스테이트는 수정된 게 없으니 빈 값 아닌가요 ? 빈 값인데 초기값이 나온다는 게 ..ㅠㅠ 미리 답변 감사합니다 선생님.
-
미해결한 입 크기로 잘라 먹는 리액트(React.js) : 기초부터 실전까지
useState() 데이터 추가 성능 질문
안녕하세요! React에서 useState()를 사용하여 배열과 같은 데이터 구조에서 자료를 추가하는 경우,다른 언어같은 경우 원소 하나만 추가하는 시간복잡도가 O(1)으로 수행하는 함수가 있는데(C++의 append 혹은 push) React에서는 항상 [newItem,...data] 이런 식으로 원소 하나 추가할 때마다, 배열의 값을 모두 새로 만드는데, 데이터가 많아질 경우 시간복잡도가 O(n)으로 비효율적일 것 같습니다. 그래서 React에는 push()같은 방식으로 데이터를 추가하는 방법이 있나요? 없다면 없는 이유가 무엇인가요??
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 프론트엔드 코스
과제부분에 조건2에 대한 질문이요
freeboard_frontend 랜딩페이지를 만들어보세요 ( 접속 시 첫 화면 )라고 나와있는데 이 조건이 무엇을 의미하나요?
-
미해결따라하며 배우는 노드, 리액트 시리즈 - 영화 사이트 만들기
npm run dev 실행시 오류
boiler plate가 설치된 폴더경로가 지정된 상태에서npm run dev를 입력했고 아래와 같은 오류가 뜹니다npm ERR! Missing script: "dev"npm ERR!npm ERR! To see a list of scripts, run:npm ERR! npm runnpm ERR! A complete log of this run can be found in:npm ERR! C:\Users\user\AppData\Local\npm-cache\_logs\2023-08-17T13_33_04_142Z-debug.logconcerently 도 설치했고 package.json에 아래 처럼스크립트 dev 설정도 잘 되어 있는데 왜 에러가 뜨는건가요 "scripts": { "start": "node server/index.js", "backend": "nodemon server/index.js", "frontend": "npm run start --prefix client", "dev": "concurrently \"npm run backend\" \"npm run start --prefix client\"" },
-
미해결처음 만난 리액트(React)
이게 왜 안될까요? 변수가 안먹어요
import React from "react"; function Book(props) { return ( <div> <h1>{'이 책의 이름은 ${props.name}입니다'}</h1> <h2>{'이 책은 총 ${props.numOfPage} 페이지로 이뤄져 있습니다.'}</h2> </div> ); } export default Book;
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 프론트엔드 코스
포트폴리오 깃 클론 주소를 못찾겠습니다.
피그마 주소밖에 확인이 안되는데,어디에 나와있는건가요..??
-
미해결따라하며 배우는 노드, 리액트 시리즈 - 기본 강의
몽고db 연결이 안됩니다..
이런 에러 뜨는데 왜 그럴까요..몽고db 연결안하면 수업에 지장이 있을까요? 수업이랑 실제 몽고db 사이트랑 달라서 많이 어렵네요
-
해결됨[리뉴얼] React로 NodeBird SNS 만들기
강의노트 링크 못찾겠습니다
안녕하세요 선생님강의노트 다운받고 싶은데 링크를 못찾겠습니다.부탁드립니다.
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 프론트엔드 코스
중고마켓 카카오맵 질문
중고마켓 구현 중에 계속 구글링해도 해결이 안돼서 질문드립니다ㅠHeader에 판매하기 Link가 있고, 클릭하면 /product/new 로 이동하게 했습니다주소창에 직접 주소를 입력해서 들어가면 에러가 안뜨는데, 버튼을 클릭해서 들어가면TypeError: window.kakao.maps.LatLng is not a constructor 에러가 발생하는데원인이 뭘까요 ....??Header <Link href="/product/new"> <a> <S.HeaderIcon> 판매하기 </S.HeaderIcon> </a> </Link>BoardWritedeclare const window: typeof globalThis & { kakao: any } export default function BoardWrite(props: IBoardWriteProps): JSX.Element { const router = useRouter() const { setValue, trigger } = useForm({ mode: "onChange", }) useEffect(() => { const script = document.createElement("script") script.src = "https://dapi.kakao.com/v2/maps/sdk.js?autoload=false&appkey=앱키" document.head.appendChild(script) script.onload = () => { window.kakao.maps.load(function () { const container = document.getElementById("map") // 지도를 담을 영역의 DOM 레퍼런스 const options = { // 지도를 생성할 때 필요한 기본 옵션 center: new window.kakao.maps.LatLng(37.462381, 126.813369), // 지도의 중심좌표. level: 3, // 지도의 레벨(확대, 축소 정도) } const map = new window.kakao.maps.Map(container, options) // 지도 생성 및 객체 리턴 }) } }, [])