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

home2 게시판 Next.js 게시판 선생님 input에 입력하면 로딩이뜨는 문제

선생님 input에 입력하면 로딩이뜨는 문제

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

    정중식
    참가자
    input을 입력하면 로딩이뜨는 문제가 있습니다.
    이미지를 선택해줘도 로딩이뜨구요 이런식으루요
    
    https://www.youtube.com/shorts/21JxruAUBCc
    
    write.js 코드는 이렇게했습니다.
    
    'use client';
    import FileUpload from '@/component/FileUpload';
    // import { authOptions } from '@/pages/api/auth/[...nextauth]';
    // import { getServerSession } from 'next-auth';
    import { useState } from 'react';
    const Write = async () => {
      // let session = await getServerSession(authOptions);
      const [imageURL, setImageURL] = useState('');
      const [imageFile, setImageFile] = useState('');
      const [title, setTitle] = useState('');
      const [contents, setContents] = useState('');
      const onFileUpload = (e) => {
        e.preventDefault();
        if (!e.target.files) return;
        const file = e.target.files[0];
        if (file) {
          let image = window.URL.createObjectURL(file);
          setImageURL(image);
          setImageFile(file);
          console.log(imageFile);
        }
      };
      const onSubmit = async (e) => {
        e.preventDefault();
        if (imageFile) {
        }
        const fileName = encodeURIComponent(imageFile.name);
        await fetch(`/api/post/new?file=${fileName}`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            title,
            contents,
          }),
        }).then((data) => {
          if (data.status === 200) {
          }
        });
      };
      return (
        <div className='form-container'>
          <h4 className='title'>글작성페이지</h4>
          <form className='post-form' onSubmit={(e) => onSubmit(e)}>
            <input
              type='text'
              value={title}
              placeholder='글제목'
              onChange={(e) => setTitle(e.target.value)}
            />
            <textarea
              type='text'
              value={contents}
              placeholder='글내용'
              onChange={(e) => setContents(e.target.value)}
            />
            <input type='file' accept='image/*' onChange={(e) => onFileUpload(e)} />
            {imageURL && (
              <img
                src={imageURL}
                alt='미리보기이미지'
                style={{ marginBottom: '1rem' }}
              />
            )}
            <button type='submit'>글작성</button>
          </form>
        </div>
      );
    };
    export default Write;
    
    loading.js 파일은 app폴더에 전역으로 설정해뒀는데, 
    문제는 loading.js파일을 삭제하고 테스트해보면 멈춥니다
    
    input이 작동을안해요.. 왜그런걸까요?
    #83187

    정중식
    참가자
    해결했습니다. async를 제거해줬어요
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 호 / 개인정보관리자 : 박종흠