Skip to content

Commit

Permalink
fix(BaseLink): Add only necessary props to the generated a
Browse files Browse the repository at this point in the history
Remove non-standard props from a and forward all the others to it
  • Loading branch information
LeonardoGentile committed Aug 30, 2017
1 parent 800818c commit d962f6c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/modules/BaseLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {ifNot} from './utils';

// TODO
// TODO: make the storeName customizable
const storeName = 'routerStore';

/**
* BaseLink component: it generates an anchor tag with href computed from props.routeName.
* BaseLink component: it generates an anchor element with href computed from props.routeName.
*
* This component won't re-render on route change
*
Expand Down Expand Up @@ -84,15 +84,16 @@ class BaseLink extends Component {
}

render() {
const {routeName, routeParams, className, dangerouslySetInnerHTML } = this.props;
// Don't add these to the 'a' element
let {routeParams, routeOptions, router, routeName, onClick, route, isActive, ...passThroughProps} = this.props;
delete passThroughProps[storeName];

// Computed props to add to 'a'
const href = this.buildUrl(routeName, routeParams);
const onClick = this.clickHandler;
const newProps = {href: href, className: className, onClick: onClick};
if (dangerouslySetInnerHTML) {
newProps['dangerouslySetInnerHTML'] = dangerouslySetInnerHTML;
}
return React.createElement('a', newProps, this.props.children);
onClick = this.clickHandler;
const newProps = {...passThroughProps, href, onClick};

return React.createElement('a', newProps, passThroughProps.children);
}
}

Expand All @@ -105,11 +106,11 @@ BaseLink.defaultProps = {

BaseLink.propTypes = {
// Defaults
routeOptions: PropTypes.object,
routeParams: PropTypes.object,
routeOptions: PropTypes.object,
// Optional
router: PropTypes.object, // when we don't pass/inject the routerStore then we need the router
routeName: PropTypes.string, // not required because of onClick could be passed instead
routeName: PropTypes.string, // not required because onClick could be passed instead
onClick: PropTypes.func,
className: PropTypes.string, // could be passed directly or forwarded (computed) from withRoute/withLink
children: PropTypes.node,
Expand Down

0 comments on commit d962f6c

Please sign in to comment.