React-devtools: "μ—…λ°μ΄νŠΈ κ°•μ‘°"λŠ” μ„±λŠ₯ μ‘°μ •λœ React 앱에 λŒ€ν•΄ 가양성을 μ œκ³΅ν•©λ‹ˆλ‹€.

에 λ§Œλ“  2018λ…„ 04μ›” 30일  Β·  3μ½”λ©˜νŠΈ  Β·  좜처: facebook/react-devtools

Reduxλ₯Ό μ‚¬μš©ν•˜μ—¬ 10개의 할일 λͺ©λ‘μ„ ν‘œμ‹œν•˜λŠ” μ΅œμ†Œ μ‘μš© ν”„λ‘œκ·Έλž¨μ„ λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€. ν•  일 쀑 ν•˜λ‚˜κ°€ 맀초 μ—…λ°μ΄νŠΈλ©λ‹ˆλ‹€. 앱은 Redux μ„±λŠ₯ FAQ 의 ꢌμž₯ 사항을 μ‚¬μš©ν•˜μ—¬ μ΅œμ ν™”λ˜μ—ˆμŠ΅λ‹ˆλ‹€. μ‹€μ œλ‘œ 앱을 μ‹€ν–‰ν•˜λ©΄ μ½˜μ†” λ‘œκ·Έμ—μ„œ λͺ©λ‘μ΄ μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ‹œμž‘ μ‹œ ν•œ 번만 λ Œλ”λ§λ˜κ³  맀초 ν•˜λ‚˜μ˜ ν•  일만 λ Œλ”λ§λ˜λŠ” 것을 λ³Ό 수 μžˆμŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ React DevToolsλŠ” 맀초 전체 λͺ©λ‘μ„ κ°•μ‘° ν‘œμ‹œν•©λ‹ˆλ‹€.

이 문제λ₯Ό 보여주기 μœ„ν•΄ μ΅œμ†Œν•œμ˜ 예λ₯Ό λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€: https://github.com/nareshbhatia/redux-performance. λˆ„κ΅°κ°€ 예제λ₯Ό 보고 이것이 React DevTools의 μ‹€μ œ λ¬Έμ œμΈμ§€ μ•„λ‹ˆλ©΄ 단지 쑰쒅석 였λ₯˜μΈμ§€ 확인해 μ£Όμ‹œκ² μŠ΅λ‹ˆκΉŒ!

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

도움을 μ£Όμ‹  @gaearon & @markerikson μ—κ²Œ κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€. λ‚˜λŠ” λ¬Έμ„œκ°€ 맀우 λͺ…ν™•ν•˜λ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€. λ‚΄κ°€ μƒκ°ν•˜μ§€ λͺ»ν•œ μœ μΌν•œ νŠΈλ¦­μ€ (@gaearon이 μ œμ•ˆν•œ λŒ€λ‘œ) ownProps λ₯Ό μ‚¬μš©ν•˜μ—¬ μ»¨ν…Œμ΄λ„ˆ λ‚΄λΆ€μ—μ„œ λ°”λ‘œ todo $λ₯Ό ν•΄κ²°ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€(전체 맡을 뷰에 μ „λ‹¬ν•˜λŠ” λŒ€μ‹ ). 이것이 λΉ„νš¨μœ¨μ μΈ λ Œλ”λ§μ˜ κ·Όλ³Έ μ›μΈμ΄μ—ˆμŠ΅λ‹ˆλ‹€. κ·€ν•˜μ˜ μ œμ•ˆμ— 따라 λ‚΄ μ €μž₯μ†Œλ₯Ό μˆ˜μ •ν–ˆμŠ΅λ‹ˆλ‹€. μ•žμœΌλ‘œ λ‹€λ₯Έ λΆ„λ“€κ»˜λ„ μœ μ΅ν•œ ꡐ윑이 λ˜μ—ˆμœΌλ©΄ ν•©λ‹ˆλ‹€.

λ‹€μ‹œ ν•œλ²ˆ κ°μ‚¬ν•©λ‹ˆλ‹€!

λͺ¨λ“  3 λŒ“κΈ€

ꡬ성 μš”μ†Œ κ°€ λ‹€μ‹œ λ Œλ”λ§λ˜λŠ” 것을 λ°©μ§€ν•˜κ³  μžˆμ§€λ§Œ React Reduxμ—μ„œ μƒμ„±λœ connect() λž˜νΌλŠ” μ—¬μ „νžˆ λ‹€μ‹œ λ Œλ”λ§λ©λ‹ˆλ‹€. 쑰언을 잘λͺ» ν•΄μ„ν–ˆμ„ μˆ˜λ„ μžˆλ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€(FAQλ₯Ό 읽지 μ•Šμ•˜κΈ° λ•Œλ¬Έμ— ν™•μ‹€ν•˜μ§€ μ•ŠμŒ). λŒ€μ‹  ν•΄μ•Ό ν•  일은 mapStateToProps κ²°κ³Όκ°€ λ³€κ²½λ˜μ§€ μ•ŠλŠ” ν•­λͺ©μ— λŒ€ν•΄ μ–•κ²Œ λ™μΌν•œμ§€ ν™•μΈν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€ .

λ‹€μŒμ€ 아이디어λ₯Ό μ œκ³΅ν•˜λŠ” diffμž…λ‹ˆλ‹€.

diff --git a/src/components/todo-view.js b/src/components/todo-view.js
index 9559a04..a3c0ac6 100644
--- a/src/components/todo-view.js
+++ b/src/components/todo-view.js
@@ -2,24 +2,12 @@ import React from 'react';
 import { PropTypes } from 'prop-types';

 export class TodoView extends React.Component {
-    static propTypes = {
-        todoId: PropTypes.number.isRequired,
-        todoMap: PropTypes.object.isRequired
-    };
-
-    shouldComponentUpdate(nextProps) {
-        const { todoId, todoMap } = this.props;
-        const { todoMap: nextTodoMap } = nextProps;
-        return todoMap[todoId] !== nextTodoMap[todoId];
-    }
-
     render() {
-        const { todoId, todoMap } = this.props;
-        console.log('-----> TodoView.render():', todoId);
+        const { todo } = this.props;

         return (
             <tr>
-                <td >{todoMap[todoId]}</td>
+                <td >{todo}</td>
             </tr>
         );
     }
diff --git a/src/containers/todo-view-container.js b/src/containers/todo-view-container.js
index b3930f0..ad3e37f 100644
--- a/src/containers/todo-view-container.js
+++ b/src/containers/todo-view-container.js
@@ -1,8 +1,8 @@
 import { connect } from 'react-redux';
 import { TodoView } from '../components/todo-view';

-const mapStateToProps = state => ({
-    todoMap: state.todoMap
+const mapStateToProps = (state, ownProps) => ({
+    todo: state.todoMap[ownProps.todoId]
 });

 export const TodoViewContainer = connect(mapStateToProps)(TodoView);

cc @markerikson FAQ의 λ‚΄μš©μ΄ μ„€λͺ…을 μ‚¬μš©ν•  수 μžˆλŠ” 경우

ν•‘ μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€. μˆ˜μ •ν•΄μ•Ό ν•  ꡬ체적인 λ‚΄μš©μ€ _생각_ν•˜μ§€ μ•Šμ§€λ§Œ @nareshbhatia , 정보가 μΆ©λΆ„ν•˜μ§€ μ•Šλ‹€κ³  μƒκ°λ˜λ©΄ Redux 리포지토리에 자유둭게 문제λ₯Ό μ œμΆœν•˜μ„Έμš”.

도움을 μ£Όμ‹  @gaearon & @markerikson μ—κ²Œ κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€. λ‚˜λŠ” λ¬Έμ„œκ°€ 맀우 λͺ…ν™•ν•˜λ‹€κ³  μƒκ°ν•©λ‹ˆλ‹€. λ‚΄κ°€ μƒκ°ν•˜μ§€ λͺ»ν•œ μœ μΌν•œ νŠΈλ¦­μ€ (@gaearon이 μ œμ•ˆν•œ λŒ€λ‘œ) ownProps λ₯Ό μ‚¬μš©ν•˜μ—¬ μ»¨ν…Œμ΄λ„ˆ λ‚΄λΆ€μ—μ„œ λ°”λ‘œ todo $λ₯Ό ν•΄κ²°ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€(전체 맡을 뷰에 μ „λ‹¬ν•˜λŠ” λŒ€μ‹ ). 이것이 λΉ„νš¨μœ¨μ μΈ λ Œλ”λ§μ˜ κ·Όλ³Έ μ›μΈμ΄μ—ˆμŠ΅λ‹ˆλ‹€. κ·€ν•˜μ˜ μ œμ•ˆμ— 따라 λ‚΄ μ €μž₯μ†Œλ₯Ό μˆ˜μ •ν–ˆμŠ΅λ‹ˆλ‹€. μ•žμœΌλ‘œ λ‹€λ₯Έ λΆ„λ“€κ»˜λ„ μœ μ΅ν•œ ꡐ윑이 λ˜μ—ˆμœΌλ©΄ ν•©λ‹ˆλ‹€.

λ‹€μ‹œ ν•œλ²ˆ κ°μ‚¬ν•©λ‹ˆλ‹€!

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰