beeimp
BeeImp
beeimp
전체 방문자
오늘
어제
  • 분류 전체보기 (110)
    • Program_Language (17)
      • Python (13)
      • Go (0)
      • JavaScript (4)
      • TypeScript (0)
      • Rust (0)
      • Solidity (0)
    • OS (8)
      • UNIX&LINUX (7)
      • Windows (0)
      • MacOS (1)
    • Front-End (19)
      • Svelte (19)
      • React (0)
    • Blockchain (6)
      • Bitcoin (0)
      • Ethereum (1)
      • Klaytn (0)
      • Project (5)
    • Data Structure&Algorithm (11)
      • Greedy (7)
      • Dynamic Programming (1)
      • Sort (0)
      • DFS & BFS (2)
      • Recursive (1)
    • Security (0)
      • SDP (0)
      • Authentication (0)
    • Network (3)
      • OpenWrt (0)
      • SDN&NFV (1)
    • Git (5)
    • IT_News (0)
    • 베타 학습단 (12)
      • SQL (12)
    • Project (1)
    • Issues (1)
    • Reviews (3)
    • I Learned (23)
      • TIL (23)
      • WIL (0)
    • Other (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 탐욕법
  • PYTHON
  • Docker
  • svelte
  • Git
  • react
  • mysql
  • Nest.js
  • solidity
  • Ethereum
  • typescript
  • 기초
  • blockchain
  • javascript
  • github
  • 블록체인
  • sql
  • greedy
  • ubuntu
  • jenkins

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
beeimp

BeeImp

I Learned/TIL

[TIL] 경고와 버전 이슈

2022. 6. 15. 01:49

[TIL] 경고와 버전 이슈

날짜

  • 2022.06.14.

목표

  • OpenSea 클론코딩 - Create 페이지 구현

내용

함수 컴포넌트 내부 Styled-Components 경고 해결

  • 함수 컴포넌트 내부에 Styled-Components를 선언하면 다음과 같은 경고 발생

      const CreateWrapper = ({ children }) => {
        const Wapper = styled.div`
    
        `;
        return (
          <Wapper>
            {children}
          </Wapper>
        );
      }
      react_devtools_backend.js:4026 The component styled.div with the id of "sc-jqUVSM" has been created dynamically.
      You may see this warning because you've called styled inside another component.
      To resolve this only create new StyledComponents outside of any render method and function component.
  • 해결방법 - 단순히 함수 컴포넌트 외부에 선언 및 정의

      const Wapper = styled.div`
    
      `;
      const CreateWrapper = ({ children }) => {
        return (
          <Wapper>
            {children}
          </Wapper>
        );
      }
  • 함수 내부의 변수를 사용하고 싶은 경우 props 사용

      const Wapper = styled.div`
        width: ${props => props.width};
      `;
      const CreateWrapper = ({ children, width="100px" }) => {
        return (
          <Wapper width={width}>
            {children}
          </Wapper>
        );
      }

Image Upload Preview

import styled from 'styled-components';
import { useRef, useState } from 'react';

const UploadInput = styled.input`
  display: none;
`;

const UploadImage = styled.div`
  position: relative;
  width: 500px;
  height: 500px;
  border: 1px solid black;
  ${(props) => props.imageUrl === '' ? undefined : `background-image: url(${props.imageUrl});`
  }
  background-size: contain;
  background-repeat: no-repeat;
`;

const fileToDataURL = (file) => new Promise((resolve, reject) => {
  const reader = new FileReader();
  reader.onload = (event) => {
    resolve(event.target.result)
  };
  reader.readAsDataURL(file);
  })

const App = ({ onChange = (e) => { console.log(e.target) } }) => {
  const uploadRef = useRef(null);
  const [dataURL, setDataURL] = useState('')

  const test = (e) => {
    const file = e.target.files[0];

    if(!file) {
      setDataURL('');
      return;
    }

    fileToDataURL(file)
      .then(dataUri => {
        setDataURL(dataUri)
      })

  }

  return (
    <>
      <UploadImage imageUrl={dataURL} onClick={() => { uploadRef.current.click() }}></UploadImage>
      <UploadInput ref={uploadRef} type={'file'} onChange={test}></UploadInput>
    </>
  );
}

export default App;
  • 참조 사이트

caver-js 버전 오류

  • 문제 - caver-js 최신 버전에 대한 오류 발생
  • 해결 - 1.5.0으로 버전 다운그레이드

결론

  • preview 기능을 모듈을 사용해서 금방 구현 가능하지만, 직접 구현해봄
    • 생각보다 어려웠음
  • caver-js 버전 이슈로 인해 몇시간을 날렸는지 모르겠다.
    • 그래도 해결!?

'I Learned > TIL' 카테고리의 다른 글

[TIL] 협업 개발 도구에는 무엇이?  (0) 2022.06.19
[TIL] well-known port  (0) 2022.06.18
[TIL] Why 토큰 이코노미? React에서 useState의 set함수는 비동기  (0) 2022.06.17
[TIL] react, ethers, payable, file  (0) 2022.06.16
[TIL] OpenSea 클론코딩 시작 및 DeSo 컨트랙트 개발  (0) 2022.06.14
    'I Learned/TIL' 카테고리의 다른 글
    • [TIL] well-known port
    • [TIL] Why 토큰 이코노미? React에서 useState의 set함수는 비동기
    • [TIL] react, ethers, payable, file
    • [TIL] OpenSea 클론코딩 시작 및 DeSo 컨트랙트 개발

    티스토리툴바