Skip to content

Commit

Permalink
Use prop-types instead of React.PropTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
fiddlerwoaroof committed Jul 9, 2017
1 parent 7136cf3 commit 9967e80
Show file tree
Hide file tree
Showing 3 changed files with 328 additions and 211 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"ramda": "^0.24.1",
"redux": "^3.6.0"
},
"optionalDependencies": {
"prop-types": "^15.5.10"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-flow": "^6.23.0",
Expand Down
9 changes: 7 additions & 2 deletions src/action-link.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Ugly way to deal with optional dependency so we don't break projects not using react.
let React = null;
let PropTypes = null;

const ActionLink = ({action, children, ...props}, {store}) => {


if (!React) {
throw new Error("You cannot use ActionLink unless react is available");
}

if (!PropTypes) {
throw new Error("You cannot use ActionLink unless prop-types is available");
}

if (!store) {
throw new Error("You cannot use ActionLink without providing store via context (possibly using react-redux Provider?)");
}
Expand All @@ -26,8 +30,9 @@ const ActionLink = ({action, children, ...props}, {store}) => {

try {
React = require('react');
PropTypes = require('prop-types');
ActionLink.contextTypes = {
store: React.PropTypes.object
store: PropTypes.object
};

} catch (e) {
Expand Down
Loading

0 comments on commit 9967e80

Please sign in to comment.