git.fiddlerwoaroof.com
src/action-link.js
40d8820d
 // Ugly way to deal with optional dependency so we don't break projects not using react.
 let React = null;
9967e804
 let PropTypes = null;
40d8820d
 
84348047
 const ActionLink = ({ action, children, ...props }, { store }) => {
40d8820d
   if (!React) {
     throw new Error("You cannot use ActionLink unless react is available");
   }
 
9967e804
   if (!PropTypes) {
     throw new Error("You cannot use ActionLink unless prop-types is available");
   }
 
40d8820d
   if (!store) {
84348047
     throw new Error(
       "You cannot use ActionLink without providing store via context (possibly using react-redux Provider?)"
     );
478c0afb
   }
 
   const renderedRoute = store.pathForAction(action);
 
   return (
84348047
     <a
       href={renderedRoute}
       onClick={ev => {
         ev.preventDefault();
         store.dispatch(action);
       }}
       {...props}
     >
       {children}
     </a>
478c0afb
   );
 };
40d8820d
 
 try {
84348047
   React = require("react");
   PropTypes = require("prop-types");
40d8820d
   ActionLink.contextTypes = {
9967e804
     store: PropTypes.object
40d8820d
   };
84348047
 } catch (e) {}
40d8820d
 
 export default ActionLink;