From aa242cf0fba6f413dce026dcf9e402d9bc75515c Mon Sep 17 00:00:00 2001 From: haerong22 Date: Tue, 22 Dec 2020 20:23:13 +0900 Subject: [PATCH] improve performance : shoudComponentUpdate, PureComponent --- react_webgame/main/RenderTest.jsx | 35 +++++++++++++++++++++++++++++++ react_webgame/main/client.jsx | 5 +++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 react_webgame/main/RenderTest.jsx diff --git a/react_webgame/main/RenderTest.jsx b/react_webgame/main/RenderTest.jsx new file mode 100644 index 00000000..ead0400f --- /dev/null +++ b/react_webgame/main/RenderTest.jsx @@ -0,0 +1,35 @@ +import React, { PureComponent } from 'react'; + +class Test extends PureComponent { + state = { + counter: 0, + string: 'hello', + number: 1, + boolean: true, + object: {}, + array: [], + }; + + // shouldComponentUpdate(nextProps, nextState, nextContext) { + // if(this.state.counter !== nextState.counter) { + // return true; + // } + // return false; + // } + + onClick = () => { + this.setState({ + array: [...this.state.array, 1], + }); + } + + render() { + console.log('렌더링', this.state); + return ( +
+ +
+ ) + } +} +export default Test; \ No newline at end of file diff --git a/react_webgame/main/client.jsx b/react_webgame/main/client.jsx index a253c913..d53cab37 100644 --- a/react_webgame/main/client.jsx +++ b/react_webgame/main/client.jsx @@ -1,6 +1,7 @@ import React from 'react'; import ReactDom from 'react-dom'; -import NumberBaseball from './NumberBaseball'; +import Test from './RenderTest'; -ReactDom.render(, document.querySelector('#root')); \ No newline at end of file + +ReactDom.render(, document.querySelector('#root')); \ No newline at end of file