• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 React 게시판 useeffect 질문

useeffect 질문

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #31520

    이영아
    참가자

    안녕하세요 선생님 강의 다듣고 프로젝트를 만들고 있는데 강의와 상관없지만 아무리 검색하고 이것저것다해봤는데 안되고 물어볼사람도 없어서 문의드립니다 ㅠㅠㅠㅠ 댓글창을 만드려고 하고 있는데 e.target.value의 값을 담은 배열은 콘솔에 잘출력이되나 concat에 담으려하니 concat is not funtion 이라는 에러가나오네요.. 타입문제인것같아 이것저것해봤는데 다안되서 문의 드립니다ㅠㅠㅠㅠ

    아래 사진은 문제가 일어난 코드이고 그아래쪽에 전체 코드 보내드립니다 ㅠㅠㅠ 

     

     


    import React,{useState,useEffect} from "react";
    import axios from 'axios';

    const Pid = (props)=>{
        let [_Photo,changePhoto]=useState([])
         
        useEffect(()=>{
         
        axios.get('https://api.pexels.com/v1/curated?page=2&per_page=40',{headers:{
          Authorization:'563492ad6f917000010000019ff210452c074bdaa37bc7093550e096'
        }}).then((result)=>{
           console.log('result',result.data.photos)
           let copy =[...result.data.photos]
           changePhoto(copy);
            <Photo></Photo>
           
        }
           
        ).catch(()=>{
          console.log("실패")
        })
        },[])
        console.log(_Photo)
        return <div>
       { <Photo Photo={_Photo} ></Photo> }
     
        </div>
      }
     
     
      const Photo =(props) =>{

      //  const 테스트 = ()=>{
      //   let 댓글업데이트= [{comment:'',id:0}]
           
      //  }
       const [댓글, 댓글변경]=useState(false)
     
       const [댓글전송,댓글전송변경]=useState(false)
       const [댓글쓰기,댓글쓰기변경]=useState('')
       let [댓글업데이트,댓글업데이트변경] =useState([])

       
       
       useEffect(()=>{
        댓글변경()
        댓글전송변경()
        댓글업데이트변경()
        return(()=>{
          댓글전송변경(false)
        })
       
             
       },[])

     

     
        return <div className="follower-border">
              {
          props.Photo.map((item,i)=>{
            return(
              <div className="container in-line" key={item.id}>
               
             <div>{item.alt}</img></div>
             <a className="user-size user-margin text-position"  href={item.photographer_url}>user: {item.photographer}</a>
               <div className="user-margin text-size text-position">  {item.alt}</div>
                <div>
                <div className="comment user-margin text-position"><button onClick={(e)=>{
                  e.preventDefault();
                    댓글변경(true)  
                }}>all comment</button></div>
               
                {
                  댓글 == true&& <div>
                  <span ><input className="input-width comment input-position"
                   onChange={(e)=>{
                        let copy = e.target.value
                        댓글쓰기변경(copy)
                         console.log('댓글쓰기',댓글쓰기)
                     
                   }}></input> </span>
                   <span><input  className=" comment input-margin" type="button" name="name" value="comment"
                   onClick={(e)=>{
                    댓글전송변경(true)
                 
                           let copy = [{comment:댓글쓰기,id:Number(item.id)}]
                           console.log(copy)
                           댓글업데이트변경.concat(copy)
                           console.log(댓글업데이트변경.comment)
                   }}></input></span>
                  </div>
                }
                <div className="user-margin comment comment-flex text-position">
                 <div>
                 
                  {댓글전송==true&&댓글업데이트[0].comment}
                  {댓글전송==true&&<div>닉네임:슈짱 </div>}
                 
                  </div>
               
                </div>
               
             
                </div>
               
             
                 
                </div>
           
            )
            })
          }        
     
               </div>
          }
       
     
          export default Pid
       

       

    #31534

    codingapple
    키 마스터

    아마 state변경함수가 아니라 state에 concat을 해야하지않을까요

    댓글업데이트.concat(copy)

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠