Skip to content

Only change state in willReceiveNewProps if the props have changed #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions dist/react-simpletabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,41 @@
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/

/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/

/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
Expand Down Expand Up @@ -107,7 +107,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
},
componentWillReceiveProps: function(newProps){
if(newProps.tabActive){ this.setState({tabActive: newProps.tabActive}) }
if(newProps.tabActive && newProps.tabActive !== this.props.tabActive){
this.setState({tabActive: newProps.tabActive});
}
},
render:function () {
var className = classNames('tabs', this.props.className);
Expand All @@ -134,8 +136,6 @@ return /******/ (function(modules) { // webpackBootstrap
onAfterChange(index, $selectedPanel, $selectedTabMenu);
}
});

e.preventDefault();
},
_getMenuItems:function () {
if (!this.props.children) {
Expand All @@ -159,7 +159,7 @@ return /******/ (function(modules) { // webpackBootstrap

return (
React.createElement("li", {ref: ref, key: index, className: classes},
React.createElement("a", {href: "#", onClick: this.setActive.bind(this, index + 1)},
React.createElement("a", {onClick: this.setActive.bind(this, index + 1)},
title
)
)
Expand Down Expand Up @@ -211,7 +211,13 @@ return /******/ (function(modules) { // webpackBootstrap
/* 2 */
/***/ function(module, exports, __webpack_require__) {

/** @jsx React.DOM */function classNames() {
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/** @jsx React.DOM *//*!
Copyright (c) 2015 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/

function classNames() {
var classes = '';
var arg;

Expand All @@ -237,11 +243,18 @@ return /******/ (function(modules) { // webpackBootstrap
return classes.substr(1);
}

// safely export classNames in case the script is included directly on a page
// safely export classNames for node / browserify
if (typeof module !== 'undefined' && module.exports) {
module.exports = classNames;
}

// safely export classNames for RequireJS
if (true) {
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() {
return classNames;
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
}


/***/ },
/* 3 */
Expand All @@ -252,3 +265,4 @@ return /******/ (function(modules) { // webpackBootstrap
/***/ }
/******/ ])
});
;
8 changes: 4 additions & 4 deletions lib/react-simpletabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ var Tabs = React.createClass({
}
},
componentWillReceiveProps: function(newProps){
if(newProps.tabActive){ this.setState({tabActive: newProps.tabActive}) }
if(newProps.tabActive && newProps.tabActive !== this.props.tabActive){
this.setState({tabActive: newProps.tabActive});
}
},
render () {
var className = classNames('tabs', this.props.className);
Expand All @@ -69,8 +71,6 @@ var Tabs = React.createClass({
onAfterChange(index, $selectedPanel, $selectedTabMenu);
}
});

e.preventDefault();
},
_getMenuItems () {
if (!this.props.children) {
Expand All @@ -94,7 +94,7 @@ var Tabs = React.createClass({

return (
<li ref={ref} key={index} className={classes}>
<a href='#' onClick={this.setActive.bind(this, index + 1)}>
<a onClick={this.setActive.bind(this, index + 1)}>
{title}
</a>
</li>
Expand Down