From 66d131fc2ab48c44474ee65a4eba134d99d8de8a Mon Sep 17 00:00:00 2001 From: xwenliang Date: Mon, 11 Jan 2016 23:02:41 +0800 Subject: [PATCH] add shouldComponentUpdate --- index.js | 16 +++++----------- package.json | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 00a1e0b..960be00 100644 --- a/index.js +++ b/index.js @@ -58,18 +58,12 @@ export default class PickerAny extends React.Component { this.setState(newState); } - //todo - /*shouldComponentUpdate(props, state, context){ - let newProps = Object.assign({}, props); - let newState = Object.assign({}, state); - let oldProps = Object.assign({}, this.props); - let oldState = Object.assign({}, this.state); - let arr = [newProps, newState, oldProps, oldState]; - for(let i in arr){ - delete arr[i].slideAnim; + shouldComponentUpdate(nextProps, nextState, context){ + if(JSON.stringify(nextState.selectedValue) === JSON.stringify(this.state.selectedValue)){ + return false; } - return JSON.stringify([newProps, newState, context]) !== JSON.stringify([oldProps, oldState, this.context]); - }*/ + return true; + } _getStateFromProps(props){ //the pickedValue must looks like [wheelone's, wheeltwo's, ...] diff --git a/package.json b/package.json index 1e96aee..e9306b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-picker", - "version": "0.2.11", + "version": "0.3.0", "description": "react-native-picker", "main": "index.js", "scripts": { -- 2.26.2