Giter VIP home page Giter VIP logo

dev-tips's Introduction

BKJang's github stats Top Langs

ReadMe Card ReadMe Card

ReadMe Card ReadMe Card

dev-tips's People

Contributors

bkjang avatar

Stargazers

 avatar

Watchers

 avatar  avatar

dev-tips's Issues

React์˜ state๋Š” ์™œ ๋ถˆ๋ณ€์„ฑ์„ ์œ ์ง€ํ•ด์•ผํ• ๊นŒ? ์™œ Immutable.js ๋ฅผ ์‚ฌ์šฉํ• ๊นŒ?

โ—๏ธ React์˜ state๋Š” ์™œ ๋ถˆ๋ณ€์„ฑ์„ ์œ ์ง€ํ•ด์•ผํ• ๊นŒ? ์™œ Immutable.js ๋ฅผ ์‚ฌ์šฉํ• ๊นŒ?

react์™€ redux์˜ ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ์ฝ๋‹ค ๋ณด๋ฉด Immutability๋ฅผ ๊ฐ•์กฐํ•˜๋Š” ๋Œ€๋ชฉ์„ ์ข…์ข… ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
์™œ ๋ถˆ๋ณ€์„ฑ(Immutability)๋ฅผ ์œ ์ง€ํ•ด์ค˜์•ผ ํ• ๊นŒ?

๋ถˆ๋ณ€์„ฑ์„ ์ง€ํ‚ค์ง€ ์•Š์œผ๋ฉด ์šฐ๋ฆฌ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ตœ์ ํ™” ํ•  ์ˆ˜ ์—†๋‹ค.

๋ฆฌ์•กํŠธ๊ฐ€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๊ณผ์ •์„ ์‚ดํŽด๋ณด์ž.

  1. setState๋ฅผ ํ˜ธ์ถœ (ํ˜น์€ ๋ถ€๋ชจ๋กœ๋ถ€ํ„ฐ props๋ฅผ ์ „๋‹ฌ ๋ฐ›์Œ)
  2. shouldComponentUpdate๋ฅผ ์‹คํ–‰ํ–ˆ๋Š”๋ฐ false๋ฅผ ๋ฆฌํ„ดํ•˜๋ฉด ์—ฌ๊ธฐ์„œ ๋ฉˆ์ถ”๊ณ , true๋ฅผ ๋ฆฌํ„ดํ•˜๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ์ด๋™
  3. ๊ฐ€์ƒ DOM๊ณผ ์‹ค์ œ DOM์„ ๋น„๊ตํ•ด์„œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์žˆ์œผ๋ฉด ํ™”๋ฉด์„ ๋‹ค์‹œ ๊ทธ๋ฆฐ๋‹ค

ํ•ต์‹ฌ์€ 2๋ฒˆ์— ์žˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ 2๊ฐœ์˜ ์ƒํƒœ๋ฅผ ๋น„๊ตํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž.

const array = [1,2,3,4];
const sameArray = array;
sameArray.push(5);

console.log(array !== sameArray); // false
const array = [1,2,3,4];
const differentArray = [...array, 5];
console.log(array !== differentArray); // true

์ฒซ ๋ฒˆ์งธ ์ฝ”๋“œ์˜ array์™€ sameArray๋ณ€์ˆ˜๊ฐ€ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ๋ฐฐ์—ด์˜ ์ฃผ์†Œ ๊ฐ’์€ ์„œ๋กœ ๊ฐ™๋‹ค. ํ•˜์ง€๋งŒ, ๋‘ ๋ฒˆ์งธ ์ฝ”๋“œ์˜ ๊ฐ๊ฐ์˜ ๋ฐฐ์—ด์€ ๋‹ค๋ฅธ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๊ฐ€์ง€๊ธฐ ๋•Œ๋ฌธ์— ๋น„๊ตํ–ˆ์„ ๋•Œ ๋‹ค๋ฅด๋‹ค๋Š” ๊ฒฐ๊ณผ ๊ฐ’์ด ๋‚˜์˜ค๊ฒŒ ๋œ๋‹ค.
์ด์™€ ๊ฐ™์ด ๋ถˆ๋ณ€์„ฑ์„ ์œ ์ง€ํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๊ฐ ๊ฐ์ฒด์˜ ๊ฐ’์ด ์•„๋‹Œ ๋ ˆํผ๋Ÿฐ์Šค ๊ฐ’๋งŒ ๋น„๊ต๋ฅผ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

์ฆ‰, shouldComponentUpdate๋‚ด์˜ ์ฝ”๋“œ๋Š” ํ•œ ์ค„์ด๋ฉด ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.

ํ•˜์ง€๋งŒ, ๋ถˆ๋ณ€์„ฑ์„ ์œ ์ง€ํ•˜๋ฉฐ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋‹ค๋ณด๋ฉด ์ƒํƒœ ์—…๋ฐ์ดํŠธ ๋กœ์ง์ด ๋ณต์žกํ•ด์งˆ ์ˆ˜ ์žˆ๋‹ค.

state = {
    where: {
        are: {
            you: {
                now: 'faded',
                away: true // ์ด ๋ถ€๋ถ„์„ ๋ฐ”๊พธ๊ณ  ์‹ถ๋‹ค
            },
            so: 'lost'
        },
        under: {
            the: true,
            sea: false
        }
    }
}
const { where } = this.state;
this.setState({
    where: {
        ...where,
        are: {
            ...where.are,
            you: {
                ...where.are.you,
                away: false
            }
        }
    }
});

์œ„์˜ ์˜ˆ์‹œ๋งŒ ๋ด๋„ ์ถฉ๋ถ„ํžˆ ๋ณต์žกํ•ด์ง€๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฐ ์ƒํƒœ ์—…๋ฐ์ดํŠธ ๋กœ์ง์„ ํŽธํ•˜๊ฒŒ ํ•ด์ฃผ๋Š” ๋Œ€ํ‘œ์ ์ธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์šฐ๋ฆฌ๊ฐ€ React๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ํŒจํ„ด ์ฒ˜๋Ÿผ ๋งŽ์ด ์‚ฌ์šฉํ•ด์™”๋˜ Immutable.js์ด๋‹ค.

์ •๋ฆฌํ•˜์ž๋ฉด, React์˜ ์ƒํƒœ๋Š” ์ปดํฌ๋„ŒํŠธ ์ตœ์ ํ™”๋ฅผ ์œ„ํ•ด ๋ถˆ๋ณ€์„ฑ์„ ์œ ์ง€ํ•ด์•ผํ•˜๋ฉฐ ์ด๋ฅผ ํŽธํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด Immutable.js๊ฐ™์€ ๋ถˆ๋ณ€ ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

๐Ÿ™ Reference

์ข€ ๋” ์•„๋ฆ„๋‹ต๊ณ  ํŽธํ•˜๊ฒŒ ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•ด๋ณด์ž! (Prettier, ESLint, Snippet)

โ—๏ธ Prettier

์ฝ”๋“œ์˜ ์Šคํƒ€์ผ์„ ์•„๋ฆ„๋‹ต๊ฒŒ ํ†ต์ผ์„ฑ ์žˆ๊ฒŒ ๋งŒ๋“ค์–ด์ค€๋‹ค.

{
  "trailingComma": "all",
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true
}

๐Ÿ”จ ESLint

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๋ฌธ๋ฒ•์„ ์ฒดํฌํ•˜๊ณ  ํ†ต์ผ์„ฑ ์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค€๋‹ค.

์ฐธ๊ณ 

// npm install eslint-config-airbnb eslint-config-prettier
"eslintConfig": {
  "extends": [
    "react-app",
    "airbnb",
    "prettier"
  ],
  "rules": {
    "no-unused-vars": 1,
    "no-console": 0,
    "react/jsx-filename-extension": 0
  }
},

์ง€๋‚˜์น˜๊ฒŒ ๋ฌธ๋ฒ• ์ฒดํฌ๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด ์ƒ์‚ฐ์„ฑ์ด ๋–จ์–ด์งˆ ์ˆ˜๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ตณ์ด ๊ผญ eslint ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ํ•„์š”๋Š” ์—†๋‹ค.

๐Ÿ‘ Snippet (์ฝ”๋“œ์กฐ๊ฐ)

์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ์ฝ”๋“œ์— ๋Œ€ํ•˜์—ฌ ๋‹จ์ถ•์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น ๋ฅด๊ฒŒ ๋งŒ๋“ค์–ด๋‚ธ๋‹ค.

์ฐธ๊ณ 

// Preferences => User Snippet
{
  "Create Functional React Component": {
    "prefix": "fc",
      "body": [
        "import React from 'react';",
	"",
	"function ${TM_FILENAME_BASE}() {",
	"  return (",
	"    <div>",
	"      ${1:Functional Component}",
	"    </div>",
	"  )",
      "}",
      "",
      "export default ${TM_FILENAME_BASE};"
      ],
      "description": "Create Functional React Component"
    }
}

Useful JS Tricks

๐Ÿ”จ Get Unique Values of an Array

var j = [...new Set([1, 2, 3, 3])]
>> [1, 2, 3]

๐Ÿ”จ Array and Boolean

filter falsy values (0, undefined, null, false, etc.) out of an array.

myArray
    .map(item => {
        // ...
    })
    // Get rid of bad values
    .filter(Boolean);

๐Ÿ”จ Create Empty Objects

Create empty object __proto__ and the usual hasOwnProperty and other object methods are not exist.

let dict = Object.create(null);

// dict.__proto__ === "undefined"
// No object properties exist until you add them

๐Ÿ”จ Merge Objects

const person = { name: 'David Walsh', gender: 'Male' };
const tools = { computer: 'Mac', editor: 'Atom' };
const attributes = { handsomeness: 'Extreme', hair: 'Brown', eyes: 'Blue' };

const summary = {...person, ...tools, ...attributes};
/*
Object {
  "computer": "Mac",
  "editor": "Atom",
  "eyes": "Blue",
  "gender": "Male",
  "hair": "Brown",
  "handsomeness": "Extreme",
  "name": "David Walsh",
}
*/

๐Ÿ”จ Require Function Parameters

const isRequired = () => { throw new Error('param is required'); };

const hello = (name = isRequired()) => { console.log(`hello ${name}`) };

// This will throw an error because no name is provided
hello();

// This will also throw an error
hello(undefined);

// These are good!
hello(null);
hello('David');

๐Ÿ”จ Destructuring Aliases

const obj = { x: 1 };

// Grabs obj.x as { x }
const { x } = obj;

// Grabs obj.x as { otherName }
const { x: otherName } = obj;

๐Ÿ”จ Get Query String Parameters

// Assuming "?post=1234&action=edit"

var urlParams = new URLSearchParams(window.location.search);

console.log(urlParams.has('post')); // true
console.log(urlParams.get('action')); // "edit"
console.log(urlParams.getAll('action')); // ["edit"]
console.log(urlParams.toString()); // "?post=1234&action=edit"
console.log(urlParams.append('active', '1')); // "?post=1234&action=edit&active=1"

๐Ÿ™ Reference

Spring ์ •์  ๋ฆฌ์†Œ์Šค 404 error

โ—๏ธ How did I encounter this issue?

Spring์—์„œ ์ •์  ๋ฆฌ์†Œ์Šค๋ฅผ ๋ชป์ฐพ์•„์˜ค๋Š” ๋ฒ„๊ทธ.

โ“ What is the cause of this issue?

<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

์œ„์™€ ๊ฐ™์ด url-pattern ์ด / ๋กœ ๋˜์–ด ์žˆ์„ ๊ฒฝ์šฐ ๋ชจ๋“  URI ์— ๋Œ€ํ•ด Servlet Mapping์„ ํ™•์ธํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ •์  ๋ฆฌ์†Œ์Šค๋“ค์€ ๋งคํ•‘์‹œํ‚ฌ์ˆ˜ ์—†์œผ๋ฏ€๋กœ 404๊ฐ€ ๋ฐœ์ƒ.

๐Ÿ”จ What have I tried? How did you finally solve it?

tomcat Module Path๋ฅผ /๋กœ ์„ธํŒ… ํ›„ reboot.

or

<servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.js</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.css</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.jpg</url-pattern>
    </servlet-mapping>

์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•ด ๋†“์œผ๋ฉด dispatcherServlet ์€ default Servlet Mapping ์„ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ๋งŒ Controller ์™€ ๋งคํ•‘ ์‹œํ‚จ๋‹ค.

ํ•˜์ง€๋งŒ ์ด์™€๊ฐ™์ด ์ •์  ๋งค์†Œ๋“œ๋“ค์— ๋Œ€ํ•ด ์ผ์ผ์ด ์—ด๊ฑฐ ํ•˜๋Š” ๊ฒƒ ๋ณด๋‹ค๋Š” Spring 3.x ์ด์ƒ๋ถ€ํ„ฐ ์ง€์›๋˜๋Š” <mvc:default-servlet-handler/> ๋กœ ๋Œ€์ฒดํ•ด์„œ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

๐Ÿ™ Reference

react-native-firebase foreground ์ƒํƒœ์—์„œ push ์ˆ˜์‹ 

โ—๏ธ How did I encounter this issue?

React Native๋ฅผ ์ด์šฉํ•˜์—ฌ ์•ฑ ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•˜๋ฉฐ push ์•Œ๋ฆผ ์ˆ˜์‹  ๊ธฐ๋Šฅ์ด ํ•„์š”.
react-native-firebase ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•˜๋˜ ์ค‘ background ์ƒํƒœ์—์„œ๋Š” push ์ˆ˜์‹ ์ด ๋ฌด๋ฆฌ ์—†์ด ๋˜๋‚˜ foreground ์ƒํƒœ์—์„œ๋Š” push ์ˆ˜์‹ ์ด ์•ˆ๋˜๋Š” ์ƒํ™ฉ์ด ์žฌํ˜„.

โ“ What is the cause of this issue?

๐Ÿ”จ What have I tried? How did you finally solve it?

๐Ÿ‘ Is there any better way?

๐Ÿ™ Reference

FOUC(Flash of Unstyled Content)

โ—๏ธ How did I encounter this issue?

โ“ What is the cause of this issue?

๐Ÿ”จ What have I tried? How did you finally solve it?

๐Ÿ‘ Is there any better way?

๐Ÿ™ Reference

JSON.stringify circular structure

โ“ What is the cause of this issue?

JSON.stringify()๋Š” ์ˆœํ™˜์ฐธ์กฐ๋ฅผ ๋ฐœ๊ฒฌํ•˜๋ฉด TypeError๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค.

var obj = { a: 1 };
obj.child = obj;
console.log( JSON.stringify( obj ) ); // TypeError: Converting circular structure to JSON

๐Ÿ”จ What have I tried? How did you finally solve it?

var cache = [];
JSON.stringify(obj, function(key, value) {
    if (typeof value === 'object' && value !== null) {
        if (cache.indexOf(value) !== -1) {
            // Circular reference found, discard key
            return;
        }
        // Store value in our collection
        cache.push(value);
    }
    return value;
});
cache = null; // Enable garbage collection

๐Ÿ‘ Is there any better way?

const getCircularReplacer = () => {
  const seen = new WeakSet();
  return (key, value) => {
    if (typeof value === "object" && value !== null) {
      if (seen.has(value)) {
        return;
      }
      seen.add(value);
    }
    return value;
  };
};

JSON.stringify(obj, getCircularReplacer());

๐Ÿ™ Reference

FormData Request

โ—๏ธ How did I encounter this issue?

react-native-image-picker๋ฅผ ์จ์„œ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๋Š” ๊ณผ์ •์—์„œ ์„œ๋ฒ„ ์ชฝ์—์„œ ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์ง€ ๋ชปํ•˜๋Š” ์ƒํ™ฉ์ด ์žฌํ˜„๋จ.

โ“ What is the cause of this issue?

Front์—์„œ๋Š” FormData์— ๋ฐ์ดํ„ฐ๋ฅผ append์‹œ์ผœ ์„œ๋ฒ„๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ์„œ๋ฒ„ ์ชฝ์—์„œ๋Š” json๋ฐ์ดํ„ฐ๊ฐ€ ๋„˜์–ด๊ฐˆ ๊ฒƒ์œผ๋กœ ์ƒ๊ฐํ•˜๊ณ  @RequestBody๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๊ณ  ์žˆ์—ˆ์Œ.
๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์˜€๋Š”๋ฐ ์ข€ ๋” ๊ผผ๊ผผํ•˜์ง€ ๋ชปํ•ด ๋ฐœ์ƒ.

๐Ÿ”จ What have I tried? How did you finally solve it?

์„œ๋ฒ„์ชฝ @RequestBody๋ฅผ @RequestPart๋กœ ์ˆ˜์ •.

//Server
@RequestPart(value = "addLogoFileIdList", required = false) MultipartFile addLogoFileIdList)
//Front
const formData = new FormData();
this.state.fileName && formData.append('addLogoFileIdList', {
      name: this.state.fileName,
      type: this.state.imageType,
      uri: Platform.OS === "android" ? this.state.imageUri : this.state.imageUri.uri.replace("file://", ""),
      data: this.state.data
});
const data = {
      storeName: this.state.storeName,
      storePhone: this.state.storePhone,
      storeAddress: this.state.storeAddress,
};
Object.keys(data).forEach(key => {
      formData.append(key, data[key]);
});

๐Ÿ™ Reference

React Native Webview callback

โ—๏ธ How did I encounter this issue?

โ“ What is the cause of this issue?

๐Ÿ”จ What have I tried? How did you finally solve it?

๐Ÿ‘ Is there any better way?

๐Ÿ™ Reference

๊ฐ’ ๋น„๊ตํ•˜๊ธฐ (Array, String, Object ...)

โ—๏ธ How did I encounter this issue?

react-router-dom ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋‚ด๋ถ€์—๋Š” ๊ฐ์ฒด์˜ ๊ฐ’์„ ๋น„๊ตํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๋‚ด๋ถ€์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค.
value-equal์ด๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ  ์ด ์ฝ”๋“œ๋ฅผ ์‹ค์ œ๋กœ ๊ฐœ๋ฐœ์‹œ์—๋„ ์ถฉ๋ถ„ํžˆ ์ ์šฉํ•ด๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋‹ค.

๐Ÿ”จ ์‹ค์ œ ๋‚ด๋ถ€ ์ฝ”๋“œ

๐Ÿ™ Reference

JS์—์„œ ์‹œ๊ฐ„์„ ์ธก์ •ํ•ด๋ณด์ž

โ—๏ธTime in JS

js๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹œ๊ฐ„์„ ์ธก์ •ํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ๋‚ด ์ฝ”๋“œ๊ฐ€ ์–ผ๋งˆ๋งŒํผ์˜ ์‹œ๊ฐ„์„ ์‚ฌ์šฉํ–ˆ๋Š”์ง€ ์•Œ๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๋‹ค.
๋˜ ์“ฐ๋กœํ‹€๋ง์ฒ˜๋Ÿผ ๋ช‡ ์ดˆ ๋™์•ˆ ์ด๋ฒคํŠธ๊ฐ€ ํ•œ ๋ฒˆ๋งŒ ๋ฐœ์ƒํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค.

๋ฌผ๋ก  ํ”„๋ก ํŠธ์˜ js ์ฝ”๋“œ์—์„œ๋Š” ์—„์ฒญ ์ •๋ฐ€ํ•œ ์‹œ๊ฐ„์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์ง€๋Š” ์•Š๋‹ค.
ํ•˜์ง€๋งŒ ์ •ํ™•๋„ ๋†’์€ ์‹œ๊ฐ„์„ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ๋Š” ์–ธ์ œ ์–ด๋–ป๊ฒŒ ์‹คํ–‰๋˜์–ด๋„ ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๋ณด์žฅํ•œ๋‹ค. ํ’ˆ์งˆ์ด ์ข‹์•„์ง„๋‹ค.

๋”ฐ๋ผ์„œ ์‹œ๊ฐ„์„ ์ธก์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋‘˜ ํ•„์š”๊ฐ€ ์žˆ๋‹ค.

js์—์„œ ์‹œ๊ฐ„์„ ์ธก์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ํฌ๊ฒŒ 4๊ฐ€์ง€๊ฐ€ ์กด์žฌํ•œ๋‹ค.

  • Date.now
  • console.time
  • process.hrtime (nodeJS)
  • performance

Date.now

Date๋Š” ๊ฐ€์žฅ ๊ณ ์ „์ ์ด๋ฉฐ ์‰ฝ๊ฒŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” API๋‹ค.

Date.now๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด 1970๋…„ 1์›” 1์ผ 0์‹œ 0๋ถ„ 0์ดˆ๋ถ€ํ„ฐ ํ˜„์žฌ๊นŒ์ง€ ๊ฒฝ๊ณผ๋œ ๋ฐ€๋ฆฌ ์„ธ์ปจ๋“œ(milliseconds)๋ฅผ Number ํƒ€์ž…์œผ๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

ํŠน์ • ์ฝ”๋“œ ์ด์ „๊ณผ ์ดํ›„์— Date.now๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ทธ ์ฝ”๋“œ์˜ ์‹คํ–‰ ์‹œ๊ฐ„์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

const start = Date.now();

let arr = ['1'];
for (let i = 0; i < 10000000; i++) {
  arr.push('' + i);
}

const end = Date.now();

console.log((end - start) / 1000);

Date.now ๋ฉ”์„œ๋“œ๋Š” ์‹œ์Šคํ…œ ์‹œ๊ฐ„์„ ๊ธฐ์ค€์œผ๋กœ ํ˜„์žฌ ํƒ€์ž„์Šคํƒฌํ”„๋ฅผ ๋ฐ›๋Š”๋‹ค. ๊ทธ๋ž˜์„œ user agent์— ๋”ฐ๋ผ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์–ด ์‹ ๋ขฐ์„ฑ์ด ๋–จ์–ด์ง„๋‹ค.

console.time

์ด๊ฑธ ์‚ฌ์šฉํ•˜๋ฉด Date.now๋ณด๋‹ค ๊ฐ„ํŽธํ•˜๊ฒŒ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

console.time('pushTest');

let arr = ['1'];
for (let i = 0; i < 10000000; i++) {
  arr.push('' + i);
}

console.timeEnd('pushTest');

pushTest๋ผ๋Š” label์„ ๋ถ™์ผ ์ˆ˜ ์žˆ๋‹ค.

ํ•˜๋Š” ์ผ์€ ๋™์ผํ•˜๋‹ค. console ๊ฐ์ฒด์— ์žˆ๋Š” profile๊ณผ ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ dev tools์—์„œ ๋” ๋‹ค์–‘ํ•œ ์ •๋ณด๋ฅผ ๋ณผ ์ˆ˜๋„ ์žˆ๋‹ค.

devtools-profiler

process.hrtime

nodejs์—์„œ๋Š” ์œ„์˜ ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•๋ณด๋‹ค ๋”์šฑ ์ •๋ฐ€ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ process.hrtime๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

์ด๋Š” nanoseconds๊นŒ์ง€ ์ •ํ™•ํžˆ ์ธก์ •๊ฐ€๋Šฅํ•˜๋ฉฐ clock drift freeํ•˜๋‹ค.

const hrstart = process.hrtime();

let arr = ['1'];
for (let i = 0; i < 10000000; i++) {
  arr.push('' + i);
}

const hrend = process.hrtime(hrstart);

console.log(hrend);
//[2, 488580674]

hrtime์€ ๋ฐ˜ํ™˜๊ฐ’์ด array์ธ๋ฐ ๊ฐ๊ฐ [seconds, nanoseconds]๋‹ค.

performance

๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” ฮผs๋ผ๊ณ  ํ‘œ๊ธฐํ•˜๋Š” ๋งˆ์ดํฌ๋กœ ์„ธ์ปจ๋“œ๊นŒ์ง€ ์ •ํ™•ํ•œ API๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ์ด performance๋Š” ์‹œ์Šคํ…œ clock๊ณผ๋Š” ๋ฌด๊ด€ํ•˜๋‹ค.

console.time์˜ ms๋Š” ๋ฐ€๋ฆฌ์„ธ์ปจ๋“œ๋กœ 1s / 1000 ์ด๋‹ค.
performance์—์„œ ์ œ๊ณตํ•˜๋Š” ฮผs๋Š” 1ms / 1000 ์ด๋‹ค.

์‚ฌ์šฉ๋ฐฉ๋ฒ•์€ Date.now์™€ ๋™์ผํ•˜๋‹ค.

const start = performance.now();

let arr = ['1'];
for (let i = 0; i < 10000000; i++) {
  arr.push('' + i);
}

const end = performance.now();

console.log((end - start) / 1000);

performance.now์˜ ๋ฐ˜ํ™˜๊ฐ’์€ DOMHighResTimeStamp๋‹ค. ์ด๋Š” ms(๋ฐ€๋ฆฌ ์„ธ์ปจ๋“œ)์ธ๋ฐ ์†Œ์ˆ˜์ ์„ ํฌํ•จํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ๋งˆ์ดํฌ๋กœ ์„ธ์ปจ๋“œ๊นŒ์ง€ ์ •ํ™•ํ•˜๋‹ค.

performance.now๊ฐ€ ์ธก์ •๋˜๋Š” ์‹œ๊ฐ„์€ performance.timing.navigationStart๋ถ€ํ„ฐ๋‹ค.
์ด ์‹œ๊ฐ„์€ ์ด์ „ document๊ฐ€ unload๋˜๋ฉฐ ์ƒˆ๋กœ์šด document๋ฅผ fetchํ•˜๋Š”(fetchStart) ์‹œ์ ์ด๋‹ค.

๋ธŒ๋ผ์šฐ์ €์—์„œ ์ œ๊ณตํ•˜๋Š” ๋ฐฉ๋ฒ•๋“ค์€ web worker๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ํ˜„์žฌ performance๊ฐ€ ๊ทธ ์ค‘์— ๊ฐ€์žฅ ์ •ํ™•ํ•œ ์‹œ๊ฐ„์„ ์ธก์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.


๐Ÿ™ Reference

position: absolute ํ™œ์šฉํ•˜๊ธฐ

โ—๏ธ How did I encounter this issue?

โ“ What is the cause of this issue?

๐Ÿ”จ What have I tried? How did you finally solve it?

๐Ÿ‘ Is there any better way?

๐Ÿ™ Reference

Form Data

โ—๏ธ How did I encounter this issue?

โ“ What is the cause of this issue?

๐Ÿ”จ What have I tried? How did you finally solve it?

๐Ÿ‘ Is there any better way?

๐Ÿ™ Reference

React Native windowsSoftInputMode ์„ค์ •

โ—๏ธ How did I encounter this issue?

TextInput์„ ์‚ฌ์šฉํ•˜์—ฌ form์„ ๋งŒ๋“ค๊ณ  ํ‚ค๋ณด๋“œ๊ฐ€ ์˜ฌ๋ผ์™”์„ ๋•Œ ์ตœํ•˜๋‹จ์˜ ๋ฒ„ํŠผ์ด ํ‚ค๋ณด๋“œ ์œ„๋กœ ํ•จ๊ป˜ ์˜ฌ๋ผ์˜ด.
ํ‚ค๋ณด๋‹ค๊ฐ€ input ์ฐฝ์€ ๋ฎ์–ด๋ฒ„๋ฆฌ๋ฉด์„œ ๋งˆ์ง€๋ง‰ ํ•ญ๋ชฉ์„ ์ž…๋ ฅํ•˜๋ ค๋ฉด ํ‚ค๋ณด๋“œ๋ฅผ ๋‚ด๋ฆฌ๊ณ  ๋‹ค์‹œ ํด๋ฆญํ•ด์•ผํ•˜๋Š” ๋ถˆํŽธํ•จ์ด ์žˆ์—ˆ์Œ.

๐Ÿ”จ What have I tried? How did you finally solve it?

windowsSoftInputMode๋ฅผ adjustPan์†์„ฑ์œผ๋กœ ์„ค์ •ํ•˜๋ฉด ํ‚ค๋ณด๋“œ๊ฐ€ ์ตœํ•˜๋‹จ์˜ ๋ฒ„ํŠผ์„ ๊ฐ€๋ฆฌ๊ณ  ์˜ฌ๋ผ์˜ด.
KeyboardAwareScrollView์ปดํฌ๋„ŒํŠธ๋กœ ํ‚ค๋ณด๋“œ๊ฐ€ ์˜ฌ๋ผ์™”์„ ๋•Œ ์Šคํฌ๋กค์„ ์ฃผ๊ณ  ์‹ถ์€ ์˜์—ญ์„ ๊ฐ์‹ธ๋ฉด ํ‚ค๋ณด๋“œ๊ฐ€ ์˜ฌ๋ผ์™€๋„ ๋งˆ์ง€๋ง‰ ํ•ญ๋ชฉ๋„ ์Šคํฌ๋กค์„ ๋‚ด๋ ค ์ž…๋ ฅ ๊ฐ€๋Šฅํ•จ.

๐Ÿ™ Reference

sessionStorage share with tabs

โ—๏ธ How did I encounter this issue?

sessionStorage๋ฅผ ์ด์šฉํ•˜์—ฌ ์ธ์ฆ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋˜ ์ค‘, ์ƒˆ๋กœ์šด ํƒญ์„ ์—ด์—ˆ๋Š”๋ฐ ์ธ์ฆ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ณต์œ ๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒ.

โ“ What is the cause of this issue?

sessionStorage๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ธŒ๋ผ์šฐ์ €๋ฅผ ๋‹ซ์œผ๋ฉด ๋ฐ์ดํ„ฐ๊ฐ€ ์‚ญ์ œ๋˜์ง€๋งŒ, ํƒญ ๊ฐ„์—๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ๊ณต์œ ๋˜์ง€ ๋ชปํ•œ๋‹ค. ํ•˜์ง€๋งŒ, localStorage๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํƒญ ๊ฐ„์˜ ๊ณต์œ ๋Š” ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ๋ธŒ๋ผ์šฐ์ € ์ฐฝ์ด ์ข…๋ฃŒ๋˜์—ˆ์„ ๋•Œ๋„ localStorage์—๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ๋‚จ์•„์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ณด์•ˆ์ƒ ๋ฌธ์ œ๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ”จ What have I tried? How did you finally solve it?

sessionStorage์™€ localStorage ๊ฐ๊ฐ์˜ ํŠน์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ํƒญ์„ ์ƒˆ๋กœ ์ผฐ์„ ๋•Œ localStorage์— ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ณ  ์ด๋ฅผ ์ƒˆ๋กœ์—ฐ ํƒญ์˜ sessionStorage์— ๋‹ด๊ณ  localStorage์˜ ๊ฐ’์€ ์ง€์šด๋‹ค. ์•ฝ๊ฐ„์˜ ์†์ž„์ˆ˜๊ธด ํ•˜์ง€๋งŒ, ์ž˜ ๋™์ž‘ํ•œ๋‹ค.

// transfers sessionStorage from one tab to another
var sessionStorage_transfer = function(event) {
  if(!event) { event = window.event; } // ie suq
  if(!event.newValue) return;          // do nothing if no value to work with
  if (event.key == 'getSessionStorage') {
    // another tab asked for the sessionStorage -> send it
    localStorage.setItem('sessionStorage', JSON.stringify(sessionStorage));
    // the other tab should now have it, so we're done with it.
    localStorage.removeItem('sessionStorage'); // <- could do short timeout as well.
  } else if (event.key == 'sessionStorage' && !sessionStorage.length) {
    // another tab sent data <- get it
    var data = JSON.parse(event.newValue);
    for (var key in data) {
      sessionStorage.setItem(key, data[key]);
    }
  }
};

// listen for changes to localStorage
if(window.addEventListener) {
  window.addEventListener("storage", sessionStorage_transfer, false);
} else {
  window.attachEvent("onstorage", sessionStorage_transfer);
};


// Ask other tabs for session storage (this is ONLY to trigger event)
if (!sessionStorage.length) {
  localStorage.setItem('getSessionStorage', 'foobar');
  localStorage.removeItem('getSessionStorage', 'foobar');
};

๐Ÿ™ Reference

two depth ์ด์ƒ์˜ ๋นˆ JS ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ด๋ณด์ž

โ—๏ธ How did I encounter this issue?

FormData๋ฅผ Server์˜ api ๊ทœ๊ฒฉ์— ๋งž์ถ”๊ธฐ ์œ„ํ•ด์„œ ๋นˆ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์•ผํ•  ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”๋ฐ ์ด ๋•Œ, ๋งค๋ฒˆ ๋นˆ ๊ฐ์ฒด์˜ NPE์ฒดํฌ๋ฅผ ์ง„ํ–‰ํ•ด์ค˜์•ผํ•˜๋Š” ๋ถˆํŽธํ•จ์ด ์กด์žฌ.

๐Ÿ”จ What have I tried? How did you finally solve it?

var MYAPP = MYAPP || {};
MYAPP.namespace = function(ns_string) {
  var parts  = ns_string.split('.'),
      parent = MYAPP,
      i;
  if (parts[0] === "MYAPP") {
    parts = parts.slice(1);
  }
  for (i = 0; i < parts.length; i += 1) {
    if (typeof parent[parts[i]] === "undefined") {
      parent[parts[i]] = {};
    }
      // ์ฐธ์กฐ๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค. ( parent -> MYAPP ์—์„œ parent -> MYAPP.parts[i]๋กœ ๋ณ€๊ฒฝ)
      parent = parent[parts[i]];
  }
  return parent;
}
MYAPP.namespace("MYAPP.modules.module2");
var module2 = MYAPP.namespace("MYAPP.modules.module2");
module2 === MYAPP.modules.module2; // true

๐Ÿ™ Reference

Webpack, Babel(Babel7) ์„ธํŒ…

โ“ What is the WebPack?

WebPack์€ ๋ชจ๋“ˆ ๋ฒˆ๋“ค๋Ÿฌ.

WebPack์€ ํ”„๋กœ์ ํŠธ ์ „์ฒด๋ฅผ ํ•œ ๋‹จ์œ„๋กœ ๋ถ„์„ํ•œ๋‹ค.
์ฆ‰, ์ง€์ •ํ•œ ๋ฉ”์ธ ํŒŒ์ผ์—์„œ ์‹œ์ž‘ํ•ด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ require(webpack commonJS ๋ชจ๋“ˆ ์ง€์›)๊ณผ import(ES6)๋ฌธ์„ ์ฐธ๊ณ ํ•ด ํ”„๋กœ์ ํŠธ์˜ ๋ชจ๋“  ์˜์กด์„ฑ์„ ์กฐ์‚ฌํ•˜๊ณ  ๋กœ๋”๋ฅผ ์ด์šฉํ•ด ์ฒ˜๋ฆฌํ•œ ํ›„ ๋ฒˆ๋“ค๋กœ ๋ฌถ์€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค.

โ“ What is the Babel?

Babel์€ ํŠธ๋žœ์ŠคํŒŒ์ผ๋Ÿฌ.

Babel์€ ES6/ES7 ์ฝ”๋“œ๋ฅผ ECMAScript5 ์ฝ”๋“œ๋กœ transpiling ํ•˜๊ธฐ ์œ„ํ•œ ๋„๊ตฌ.(๊ผญ ES5๊ฐ€ ๋  ํ•„์š”๋Š” ์—†๋‹ค.)
Babel์€ ๋‹ค์–‘ํ•œ ์ž‘์€ ๋ชจ๋“ˆ๋“ค๋กœ ๊ตฌ์„ฑ๋˜๋ฉฐ ๋‹ค์–‘ํ•œ ๋ชจ๋“ˆ์„ ๋‹ด๋Š” ์ผ์ข…์˜ ์ƒ์ž ์—ญํ• ์„ ํ•œ๋‹ค.
์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผ ํ•˜๊ธฐ ์œ„ํ•ด ์ž‘์€ ๋ชจ๋“ˆ๋“ค(ex. presets)์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ™ Reference

Time Slider Debouncing

โ—๏ธ How did I encounter this issue?

Time Slider๊ฐ€ ์ด๋™ํ•  ๋•Œ ๋งˆ๋‹ค ์ง€๋‚˜์น˜๊ฒŒ ๋งŽ์€ ์š”์ฒญ์ด ๋ฐœ์ƒ.
์‹œ๊ฐ„๋ณ„๋กœ HeatMap์„ ๋ณด์—ฌ์ค„ ํ•„์š”๊ฐ€ ์žˆ์–ด Time Slider๋ฅผ ์ด์šฉํ•ด ๊ตฌํ˜„ํ•˜๋˜ ์ค‘ ๋ฐœ์ƒ.

โ“ What is the cause of this issue?

Time Slider์˜ ๋ฏธ์„ธํ•œ ์›€์ง์ž„์—๋„ ์š”์ฒญ์ด ๋ฐœ์ƒํ•˜์—ฌ ์ง€๋‚˜์น˜๊ฒŒ ๋งŽ์€ ์ž์› ์†Œ๋ชจ.

๐Ÿ”จ What have I tried? How did you finally solve it?

Debouncing์„ ์ ์šฉํ•ด ์ผ์ • ์ฃผ๊ธฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋งˆ์ง€๋ง‰ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ๋น„๋™๊ธฐ ์š”์ฒญ๋งŒ ์ˆ˜ํ–‰.

function onChangeSliderWithPlay() {	
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(function () {
            //๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ
            renderDataWithPlay();
        }, 500);
    }

๐Ÿ‘ Is there any better way?

๊ฒฐ๊ตญ, Scroll ์ด๋ฒคํŠธ์˜ ์ตœ์ ํ™”์™€ ํฌ๊ฒŒ ๋‹ค๋ฅด์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— rAF๋ฅผ ์ด์šฉํ•œ ์Šคํฌ๋กค ์ด๋ฒคํŠธ ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•˜์ง€ ์•Š์„๊นŒ?

๐Ÿ™ Reference

React Native Scroll Animation

โ—๏ธ What is the issue?

ํ•œ ํ™”๋ฉด์— 3๊ฐœ์˜ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ๊ณ  ๊ฐ€์žฅ ์•„๋ž˜์— ์žˆ๋Š” ์ปดํฌ๋„ˆํŠธ๊ฐ€ ์Šคํฌ๋กค ์ปดํฌ๋„ŒํŠธ์ด๋‹ค.
์Šคํฌ๋กค ์ปดํฌ๋„ŒํŠธ๋ฅผ ์•„๋ž˜๋กœ ๋‚ด๋ ธ์„ ๋•Œ ์œ„์˜ ์ปดํฌ๋„ŒํŠธ๋“ค์€ ์ ‘ํžŒ ์ƒํƒœ๋กœ ์ตœ์ƒ๋‹จ์—๋Š” To Top ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ํ™”์‚ดํ‘œ๊ฐ€ ํ•จ๊ป˜ ํ‘œ์‹œ๋˜์–ด์•ผ ํ•œ๋‹ค.

๐Ÿ”จ How did you finally solve it?

๐Ÿ™ Reference

HTTP ์ฟ ํ‚ค(Cookie)

โ—๏ธ How did I encounter this issue?

โ“ What is the cause of this issue?

๐Ÿ”จ What have I tried? How did you finally solve it?

๐Ÿ‘ Is there any better way?

๐Ÿ™ Reference

์‚ฌ์šฉํ•˜๊ธฐ ์ข‹์€ JS ์ •๊ทœ ํ‘œํ˜„์‹

๐Ÿ”จ What have I tried? How did you finally solve it?

๊ทœ์น™ ๊ตฌํ˜„ ์„ค๋ช…
๋ชจ๋“  ๊ณต๋ฐฑ ์ฐพ๊ธฐ /\s/g ๋„์–ด์“ฐ๊ธฐ, ํƒญ, ์ค„๋ฐ”๊ฟˆ ๊ฐ์ง€
ํœด๋Œ€์ „ํ™”๋ฒˆํ˜ธ 01[016789]\D?\d{3,4}\D?\d{4} 010-1234-5678, 01012345678, 010.1234.5678
์ด๋ฉ”์ผ ์ฒดํฌ /^0-9a-zA-Z@0-9a-zA-Z.[a-zA-Z]{2,3}$ [email protected]

๐Ÿ™ Reference

nth-child vs nth-of-type

โ—๏ธ How did I encounter this issue?

โ“ What is the cause of this issue?

๐Ÿ”จ What have I tried? How did you finally solve it?

๐Ÿ‘ Is there any better way?

๐Ÿ™ Reference

Animation when browser window is minimized

โ—๏ธ How did I encounter this issue?

์žฌ์ƒ ๋ฒ„ํŠผ(โ–ถ)์„ ํด๋ฆญํ–ˆ์„ ๋•Œ, Time Slider ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์‹คํ–‰๋˜๋ฉฐ ํ•ด๋‹น ์‹œ๊ฐ„๋Œ€์— ๋งž๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ Œ๋”๋งํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๋Š” ์ค‘ ๋ฐœ๊ฒฌ.
๊ธฐ์กด์—๋Š” setInterval์„ ์ด์šฉํ•ด ํ•ด๋‹น ์‹œ๊ฐ„๋Œ€์˜ ๋ฐ์ดํ„ฐ ์š”์ฒญ ํ›„ ๋ Œ๋”๋ง.

๋ธŒ๋ผ์šฐ์ € ์ฐฝ์„ ์ตœ์†Œํ™”ํ–ˆ์„ ๋•Œ๋„ Time Slider๊ฐ€ ๋™์ž‘ํ•˜๋„ค์š”. ๋ธŒ๋ผ์šฐ์ € ์ฐฝ์ด ์ผœ์ ธ ์žˆ์„ ๊ฒฝ์šฐ์—๋งŒ Time Slider๊ฐ€ ๋™์ž‘ํ•˜๋„๋ก ํ•ด์ฃผ์„ธ์š”...

โ“ What is the cause of this issue?

setInterval์€ ๋ธŒ๋ผ์šฐ์ €์˜ ์ตœ์ ํ™” ์ƒํƒœ์™€ ๊ด€๊ณ„ ์—†์ด clearInterval์„ ํ•ด์ฃผ๊ธฐ ์ „์—๋Š” ๊ณ„์†ํ•ด์„œ ๋™์ž‘ํ•จ.

๐Ÿ”จ What have I tried? How did you finally solve it?

์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ตฌํ˜„์œผ๋กœ ๋งŽ์ด ์“ฐ์ด๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ velocity.js์—์„œ ๋‚ด๋ถ€์ ์œผ๋กœ rAF์„ ์ด์šฉํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๊ตฌํ˜„ํ•œ๋‹ค๋Š” ๊ฒƒ.
rAF(requestAnimationFrame)๋Š” ๋ธŒ๋ผ์šฐ์ €์˜ ์ตœ์ ํ™” ์ƒํƒœ๋ฅผ ๊ณ ๋ คํ•˜์—ฌ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ์‹คํ–‰.
๋ธŒ๋ผ์šฐ์ € ํ™”๋ฉด์˜ ์ถ•์†Œ๋‚˜ ํ™”๋ฉด ์ „ํ™˜์— ๋”ฐ๋ฅธ ์• ๋‹ˆ๋ฉ”์ด์…˜์˜ ํ”„๋ ˆ์ž„ ๋ˆ„๋ฝ์„ ๋ง‰์„ ์ˆ˜ ์žˆ๋„๋ก ๊ตฌํ˜„.

๐Ÿ™ Reference

react-navigation ํ™”๋ฉด ์ด๋™์‹œ ๋ฆฌ๋กœ๋“œ

โ—๏ธ How did I encounter this issue?

ํ™”๋ฉด ์ดˆ๊ธฐ ๋ Œ๋”๋ง ์ดํ›„ ๋‹ค์‹œ ๊ฐ™์€ ํ™”๋ฉด์œผ๋กœ ๋Œ์•„์˜ฌ ๊ฒฝ์šฐ, ํ•ด๋‹น ํ™”๋ฉด์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ๋กœ ์œ ์ง€๋จ.

โ“ What is the cause of this issue?

react-naviagtion ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ navigate() ํ•จ์ˆ˜ ์‚ฌ์šฉ ์‹œ route๊ฐ€ ์žˆ์œผ๋ฉด ํ•ด๋‹น route๋กœ ์ด๋™ํ•˜๊ณ  ์—†์œผ๋ฉด ์Šคํƒ์— ๋„ฃ๋Š”๋‹ค. ์ฆ‰, ์ดˆ๊ธฐ route๊ฐ€ ์Šคํƒ์— ์กด์žฌํ•˜๋ฉด ๊ทธ route๋กœ ์ด๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ์ง€๋œ๋‹ค.
์ƒˆ๋กœ๊ณ ์นจ์ด ๊ทธ ํ™”๋ฉด์œผ๋กœ ๋„˜์–ด๊ฐˆ ๋•Œ๋งˆ๋‹ค ํ•„์š”ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๊ฒฐ์ด ํ•„์š”.

๐Ÿ”จ What have I tried? How did you finally solve it?

์ฒ˜์Œ์—๋Š” ๋ฌด์กฐ๊ฑด ์Šคํƒ์— route๋ฅผ ๋„ฃ๋Š” push() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ–ˆ์—ˆ์ง€๋งŒ ์„ฑ๋Šฅ์ƒ ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๊ณ  StackNavigator๋ฅผ ์ƒˆ๋กœ ๊ตฌ์„ฑํ•˜๋„๋ก ๊ตฌํ˜„ํ•˜์˜€๋‹ค.

StackNavigator๋ฅผ ์ƒˆ๋กœ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด NavigationActions๋ฅผ ๊ฐ€์ ธ์˜จ ๋’ค, StackNavigator๋ฅผ reset()ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒˆ๋กœ ๊ตฌ์„ฑํ–ˆ๋‹ค.

import { NavigationActions, StackActions } from 'react-navigation';

changeScreen( screenName ){
        const resetAction = StackActions.reset({
            index: 0,
            actions: [NavigationActions.navigate({ routeName : screenName })]
        });
        navigation.dispatch(resetAction);
    }

๐Ÿ™ Reference

External Component๋ฅผ Styeld Components๋กœ ๊ฐ์ŒŒ์„ ๋•Œ ์—๋Ÿฌ ํ•ด๊ฒฐ

โ—๏ธ How did I encounter this issue?

External Component๋ฅผ styled-componets๋ฅผ ์ด์šฉํ•ด์„œ styling์„ ํ•˜๋Š” ๊ณผ์ •์—์„œ ๋„˜๊ธด property๋ฅผ Styled Component์—์„œ ๊ทธ๋Œ€๋กœ ๋ฐ›์•„์ผ๋‹ค.

๊ทธ ๊ฒฐ๊ณผ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

Warning: React does not recognize the '[ํ”„๋กœํผํ‹ฐ ๋ช…]' prop on a DOM element.

๐Ÿ”จ What have I tried? How did you finally solve it?

const Input = styled(({ isDirty, ...rest }) => (
  <StyledInput {...rest} />
))`
  ${({ isDirty }) =>
    isDirty &&
    css`
      border: 1px solid rgba(48, 61, 220, 0.25);
      background: rgba(142, 172, 255, 0.07);
    `};
`;

๐Ÿ™ Reference

Throttling & Debouncing Simple Util

โ—๏ธ Throttling

function throttled(delay, fn) {
  let lastCall = 0;
  return function (...args) {
    const now = (new Date).getTime();
    if (now - lastCall < delay) {
      return;
    }
    lastCall = now;
    return fn(...args);
  }
}

โ—๏ธ Debouncing

function debounced(delay, fn) {
  let timerId;
  return function (...args) {
    if (timerId) {
      clearTimeout(timerId);
    }
    timerId = setTimeout(() => {
      fn(...args);
      timerId = null;
    }, delay);
  }
}

๐Ÿ™ Reference

React Native Multiple Dialog in iOS

โ—๏ธ How did I encounter this issue?

ํšŒ์› ํƒˆํ‡ด ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ ํ™•์ธ๊ณผ ์ทจ์†Œ ๋ฒ„ํŠผ์„ ๊ฐ€์ง„ ๋ชจ๋‹ฌ๊ณผ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€๋ฅผ ํฌํ•จํ•˜๋Š” ํ™•์ธ ๋ฒ„ํŠผ๋งŒ ๊ฐ€์ง„ Dialog์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ๊ฐ ๊ตฌํ˜„.
ํ™•์ธ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ํšŒ์› ํƒˆํ‡ด ์š”์ฒญ ์‹œ android์—์„œ๋Š” ์ž˜ ๋™์ž‘ํ•˜๋‚˜ ios์—์„œ๋Š” ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€๋ฅผ ํฌํ•จํ•œ ๋ชจ๋‹ฌ ์ฐฝ์ด ๋œจ์ง€ ์•Š๋Š” ๋ฒ„๊ทธ๊ฐ€ ๋ฐœ์ƒ.
<RCTModalHostViewController... which is already presenting

โ“ What is the cause of this issue?

iOS์—์„œ๋Š” Dialog์ปดํฌ๋„ŒํŠธ๋ฅผ 2๊ฐœ ์ด์ƒ ๋™์‹œ์— ๋„์šธ ์ˆ˜ ์—†๋‹ค.
๊ทธ๋ ‡๋‹ค๋ฉด, ๊ธฐ์กด Dialog์„ ๋„๊ณ  ๋„์šฐ๋ฉด ๋˜์ง€ ์•Š์„๊นŒ?
๋ถ„๋ช…ํžˆ setState์˜ callback์—์„œ ๊ทธ ๋‹ค์Œ ๋ฒˆ Dialog์„ ๋„์› ๋Š”๋ฐ ๋™์ž‘ํ•˜์ง€ ์•Š์Œ.(๊ฐ™์€ ์—๋Ÿฌ ๋ฐœ์ƒ)

๐Ÿ”จ What have I tried? How did you finally solve it?

nested component๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ํ•œ๋‹ค.
๋‹ค๋งŒ, ๋‚ด๊ฐ€ ์‚ฌ์šฉํ•œ ๊ฒƒ์€ react-native-dialog๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— nested component๋กœ ์ปค์Šคํ„ฐ ๋งˆ์ด์ง•ํ•˜์ง€ ์•Š๊ณ  ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋‹ค๋ฅธ props๋ฅผ ๋„˜๊ฒจ Dialog๊ฐ€ ํ•˜๋‚˜๋งŒ ์žˆ๋„๋ก ์œ ์ง€ํ–ˆ๋‹ค.

๐Ÿ™ Reference

React Native device geolocation

โ—๏ธ How did I encounter this issue?

์ฒ˜์Œ์—๋Š” react-native-community/react-native-geolocation ์‚ฌ์šฉํ•˜์˜€๋‹ค๊ฐ€ ์‚ฌ์šฉ์ž์—๊ฒŒ ์œ„์น˜ ์ •๋ณด ๊ถŒํ•œ์— ๋Œ€ํ•ด ๋ฌผ์–ด๋ณด๋Š” ํ™•์ธ ์ฐฝ์„ ๋„์šฐ๊ณ  ์•ฑ์ด ๋น„์ •์ƒ ์ข…๋ฃŒ๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒ.

๐Ÿ”จ What have I tried? How did you finally solve it?

JS์˜ navigator.geolocation ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐœ๋ฐœ

๐Ÿ™ Reference

์„œ๋ฒ„ Locale ์„ธํŒ…

โ—๏ธ How did I encounter this issue?

React Native์— Spring Framework๋ฅผ ์ด์šฉํ•œ ํ”„๋กœ์ ํŠธ ์ค‘ Front์—์„œ ์„ธํŒ…ํ•œ ์–ธ์–ด ์„ค์ •์„ ์„œ๋ฒ„์—์„œ ๋‹ค์‹œ ์„ธํŒ…ํ–ˆ์„ ๋•Œ ์„œ๋ฒ„ ์ชฝ์—์„œ๋Š” ์ œ๋Œ€๋กœ ๋จน์ง€ ์•Š์•„ ์„œ๋ฒ„๋กœ ๋ถ€ํ„ฐ ๋ฐ›์€ ๋ฐ์ดํ„ฐ๊ฐ€ default Locale๋กœ ๋งคํ•‘๋œ ๊ฐ’์ด ๋„˜์–ด์˜ด.

โ“ What is the cause of this issue?

Front์—์„œ ์–ธ์–ด ์„ค์ • ๊ธฐ๋Šฅ์„ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ์„œ๋ฒ„์—๋„ ํ•ด๋‹น ๊ฐ’์œผ๋กœ Locale ์„ธํŒ…์„ ํ•ด์ฃผ๊ณ  ์žˆ์Œ.
๋””๋ฒ„๊น… ๊ฒฐ๊ณผ, BaseLocaleAspect์—์„œ ๋ฐ›๋Š” HttpServletRequest์˜ locale ๊ฐ’์ด ๊ฐ„ํ—์ ์œผ๋กœ ์›ํ•˜๋Š” ๊ฐ’์œผ๋กœ ์ œ๋Œ€๋กœ ์„ธํŒ…๋˜์ง€ ์•Š๊ณ  ์š”์ฒญ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธ.

๐Ÿ”จ What have I tried? How did I finally solve it?

1๋ฒˆ : ์ž˜ ์•ˆ๋จ..

BaseLocaleAspect์—์„œ execution์„ ์ˆ˜์ •ํ•˜์—ฌ ๋ชจ๋“  rest ์ปจํŠธ๋กค๋Ÿฌ๋กœ ์ด๋™ ์ „์— ํƒ€๋„๋ก ์ˆ˜์ •>

  • @Before("execution(* com.blockware.keeper.app.server.*.rest.*.*(..))")

๊ฒฐ๊ณผ์ ์œผ๋กœ 1๋ฒˆ ๋ฐฉ๋ฒ•์ด ๋งž์•˜๊ณ  ๊ฐœ๋ฐœ ์„œ๋ฒ„ ์ชฝ ์–ธ์–ด ์„ค์ • ๊ด€๋ จ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•˜๋Š” ๊ณผ์ •์— ๊ธฐ์กด์— ์‚ฌ์šฉํ•˜๋˜ jarํŒŒ์ผ์ด ๊ฐœ๋ฐœ ์„œ๋ฒ„ ์ชฝ์— ๋‚จ์•„ ์žˆ์–ด ๋‚ฌ๋˜ ์˜ค๋ฅ˜์˜€์Œ.

๊ธฐ์กด jarํŒŒ์ผ์„ ์‚ญ์ œํ•˜๋‹ˆ ์ž˜ ๋™์ž‘ํ•จ.

์ƒํ™ฉ์— ๋งž์ถฐ ์‚ฌ์šฉํ•˜๋Š” console

@SeonHyungJo ๋‹˜์˜ ๊ธ€์„ ๋ณด๊ณ  ๋ฌธ๋“ ์ƒ๊ฐ์ด ๋“ ๊ฑด๋ฐ ๊ธ€์˜ ๋‚ด์šฉ๋Œ€๋กœ console.log์˜ console์—๋Š” ํ•˜์œ„ ๋ฉ”์„œ๋“œ๊ฐ€ ์กด์žฌํ•  ๊ฒƒ์ด๋‹ค. ์ด๋ฅผ ์ž˜ ์ •๋ฆฌํ•ด๋‘์…”์„œ ๋งํฌ๋ฅผ ๊ฑธ์–ด๋‘”๋‹ค.

๐Ÿ™ Reference

no-cache vs no-store

โ—๏ธ How did I encounter this issue?

โ“ What is the cause of this issue?

๐Ÿ”จ What have I tried? How did you finally solve it?

๐Ÿ‘ Is there any better way?

๐Ÿ™ Reference

React.memo๋ฅผ ์ปดํฌ๋„ŒํŠธ ๋ฆฌ๋ Œ๋”๋ง ์ตœ์ ํ™”

โ—๏ธ How did I encounter this issue?

๋ Œ๋”๋ง ์ตœ์ ํ™”๋ฅผ ์ง„ํ–‰ํ•˜๋˜ ์ค‘, React.memo๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ถˆํ•„์š”ํ•œ ๋ Œ๋”๋ง์„ ์ค„์ด๋˜ ์ค‘, ๊ธฐ์กด ๊ธฐ๋Šฅ์ด ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋Š” ๋ฒ„๊ทธ๊ฐ€ ๋ฐœ์ƒ.

โ“ What is the cause of this issue?

React.memo์˜ ๋‘๋ฒˆ ์งธ ์ธ์ž๋กœ๋Š” propsAreEqual ํ•จ์ˆ˜๋ฅผ ๋„˜๊ธธ ์ˆ˜ ์žˆ๋Š”๋ฐ ๊ธฐ์กด์˜ state๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋˜ ํ•จ์ˆ˜์—์„œ ํ•จ์ˆ˜ํ˜• ์—…๋ฐ์ดํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„ ํ•ด๋‹น ํ•จ์ˆ˜๊ฐ€ ์ตœ์‹  state๊ฐ’์„ ์ฐธ์กฐํ•˜์ง€ ๋ชปํ•ด์„œ ๋ฐœ์ƒ.

๐Ÿ”จ What have I tried? How did you finally solve it?

export default React.memo(
  UserDetail,
  (prevProps, nextProps) => prevProps.userData === nextProps.userData
);

์œ„์™€ ๊ฐ™์ด ๋‘๋ฒˆ์งธ ์ธ์ž๋กœ props๋ฅผ ๋น„๊ตํ•  ์ˆ˜ ์žˆ๊ณ  true๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋ฆฌ๋ Œ๋”๋ง์„ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
๋‹จ, ์œ„์˜ ๋กœ์ง์ด ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๋ ค๋ฉด ํ•ด๋‹น ์ƒํƒœ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋Š” ํ•จ์ˆ˜์—์„œ ํ•จ์ˆ˜ํ˜• ์—…๋ฐ์ดํŠธ๋ฅผ ํ†ตํ•ด ๋ณ€๊ฒฝํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

// Bad
setUserData({
  ...userData,
  [e.target.name]: [e.target.value]
})
// Good
setUserData(prevState => {
  const { name, value } = e.target;
  return {
    ...prevState,
    name: value
  }
})

๐Ÿ™ Reference

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.