본문 바로가기

IT Note/React18

728x90
Safari issue #html2canvas dom-to-image-more React.js 개발을 진행하며 아래 요구사항에 부합하는 라이브러리를 찾고 적용한 히스토리를 남긴다. 요구사항Dom Element를 이미지로 변환하고자 한다.배경이 투명한 PNG로의 변환을 원한다.Chrome, Safari 등의 브라우저에서 호환이 되어야 한다.이미지 생성 속도가 빠르고 화질 저하가 없어야 한다. 시도 1. dom-to-image-more (v3.5.0) 라이브러리 사용결과는 실패였다. Chrome 브라우저에선 빠르고 정상적으로 작동되었으나, Safari, Firefox 브라우저에선 이미지가 정상적으로 생성되지 않음을 확인하였다. 확인해보니 Safari를 제대로 지원하고 있지 않더라. 시도 2. html2canvas 로 변경결과는 실패였다. 역시 Chrome 브라우저에선 빠르고 정상적으로.. 2025. 4. 23.
Error #self.processResponse is not a function Chrome의 WhatRuns extension 을 사용하는 중이라 충돌되어 생긴 에러였고, extention 삭제 후 해결되었다. 참고출처: https://github.com/vercel/next.js/discussions/33355#discussioncomment-2072168 2023. 2. 2.
Next.js #Image src - External CDN image is not visible Next.js src 에 외부 CDN(External) 정보를 넣으니 이미지 출력이 안되었다. 출력 방법은 간단하다. Image loader 를 사용하면 된다. import Image from 'next/image' const myLoader = ({ src, width, quality }) => { return `https://example.com/${src}?w=${width}&q=${quality || 75}` } const MyImage = (props) => { return ( ) } https://nextjs.org/docs/api-reference/next/image#loader next/image | Next.js Enable Image Optimization with the built-i.. 2022. 10. 6.
React #Redux What Is Cross-Component / App-Wide State? Local State State that belongs to a single component E.g. listening to user input in a input field; toggling a "show more" details field Should be managed component-internal with useState() / useReduce() Cross-Component State State that affects multiple components E.g. open/ closed state of a modal overlay Requires "props chains" / "prop drilling" App-Wi.. 2022. 9. 24.
React #Building Custom Hooks What are "Custom Hooks"? Outsource stateful logic into re-usable functions Unlike "regular functions", custom hooks can use other React hooks and React state The name must start with 'use' Sample Code src/hooks/use-http.js import { useState, useCallback } from 'react'; const useHttp = () => { const [isLoading, setIsLoading] useState(false); const [error, setError] useState(null); const sendReque.. 2022. 9. 24.
React #Rules of Hooks React Rules of Hooks Only call React Hooks in React Functions React Component Functions Custom Hooks Only call React Hoos at the Top Level Don't call them in nested functions Don't call them in any block statements + extra, unoffical Rule for useEffect(): ALWAYS add everything you refer to inside of useEffect() as a dependency useEffect(() => { setFormIsValid(email && password) }, [email]); // (.. 2022. 9. 24.
React #Understanding useReducer() useReducer() const [state, dispatchFn] = useReducer(reducerFn, initialState, initFn); state: The state snapshot used in the component re-render/ re-evaluation cycle dispatchFn: A function that can be used to dispatch a new action (i.e. trigger an update of the state) reducerFn: (prevState, action) => new State / A function that is triggered automatically once an action is dispatched (via dispatc.. 2022. 9. 24.
React #mongoose #페이지네이션 구현 React와 mongoose로 페이지네이션 구현 mongoose란? mongoose란, mongoDB라는 NoSQL 데이터베이스를 지원하는 노드의 확장모듈이다. mongoose는 mongoDB의 ODM(Object Document Mapping)이다. 문서를 DB에서 조회할 때 자바스크립트 객체로 바꿔주는 역할을 한다. 페이지네이션이란? 화면에 출력할 데이터 양이 많은 경우 한 화면에 전부 보여줄 수 없어 끊어 보여주는 것을 말한다. 페이지네이션 함수 find() : 조회 sort() : 순서대로 조회 limit() : 조회 개수 skip() : 넘길 개수 lean() : plain JSON 객체를 받아온다. 직접 쿼리를 작성해서 페이지 기능 구현 Post 목록을 조회하는 listAPI이다. Post.f.. 2021. 3. 17.
React #joi 로 유효성 검증하기 joi 설치 및 사용 joi는 유효성 검증을 보다 수월하게 해주는 라이브러리입니다. 아래 명령어로 joi를 설치합니다. $ yarn add joi 게시글을 작성하는 코드입니다. joi를 활용하여 데이터 타입, 필수여부 등을 체크하여 결과를 리턴합니다. (...) const Post = require('../../models/post'); const Joi = require('joi'); /* POST /api/posts { title, body, tags } */ exports.write = async (ctx) => { // 객체가 지닌 값들을 검증 const schema = Joi.object().keys({ title: Joi.string().required(), // 뒤에 required를 붙여 .. 2021. 3. 17.
React #라우트 코드 스플리팅 #비동기적으로 코드 불러오기 청크(chunk) 생성 페이지에서 필요한 코드들만 불러오려면, 청크(chunk)를 생성해야 한다. SplitMe.js 파일을 AsyncSplitMe.js 파일에서 비동기적으로 불러오는 소스이다. SplitMe.js import React from 'react'; const SplitMe = () => { return ( 청크 ); }; export default SplitMe; AsyncSplitMe.js import React, { Component } from 'react'; class AsyncSplitMe extends Component { state = { SplitMe: null } loadSplitMe = () => { // 비동기적으로 코드를 불러옵니다. 함수는 Promise를 결과로 반환.. 2021. 3. 15.
728x90
728x90