-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add Switch and Link components #6
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments. I also did some more improvements in #7 and left out some that you did here (to avoid conflicts).
README.md
Outdated
npm install --save bs-react-router | ||
``` | ||
|
||
Then add bs-react-router to bs-dependencies in your bsconfig.json: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: formatting with backticks
Add `bs-react-router` to your `bs-dependencies`: **bsconfig.json**
} | ||
``` | ||
|
||
## Example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: we can move the examples to actual *.re
files, you know for sure then if it compiles ;)
E.g. https://github.com/reasonml-community/bs-downshift/tree/master/examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is a very good point ! Good catch !
package.json
Outdated
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "bs-react-router", | |||
"version": "1.1.1", | |||
"version": "1.1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I would avoid bumping the version in a PR, it should be done separately
- it should be a
minor
bump, not apatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely !! @bassjacob this is not a patch
, this is a minor
version cause of this change from this comment #6 (comment)
package.json
Outdated
"react-router": "^4.1.1", | ||
"react-router-dom": "^4.1.1", | ||
"react-router": "^4.2.0", | ||
"react-router-dom": "^4.2.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can leave those out, I've done this in my PR #7 and have a couple more changes (just to avoid conflicts 😉)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just a quick update, I remove them. You can add them in PR #7
src/reactRouter.re
Outdated
[@bs.module "react-router-dom"] external _switch : ReasonReact.reactClass = "Switch"; | ||
let make = (children) => | ||
ReasonReact.wrapJsForReason( | ||
~reactClass=_switch, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: you can simply name the external reactClass
, then you can avoid passing the variable
[@bs.module "react-router-dom"] external reactClass : ReasonReact.reactClass = "Switch";
ReasonReact.wrapJsForReason(~reactClass, ~props=Js.Obj.empty(), children);
[@bs.module "react-router-dom"] external link : ReasonReact.reactClass = "Link"; | ||
let make = | ||
( | ||
~_to: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use _to
or to_
? Do you know if there is a convention for such cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a good question ! My guess is to_
because _to
looks like a non-used variable so I change uses.
Hello! Sorry for the churn, but we've made a router today, so I'm planning to move this into the reasonml-old org. Though maybe some of you would like to maintain it? |
examples/reason_react_router.re
Outdated
|
||
<Switch> | ||
<Route path="/" exact=true component=(() => <HomePage />) /> | ||
<Route path="/user" component=(() => <UserPage />) /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: provide a comment that explain why you wrap the component into a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also be careful that if you keep it like this the UserPage
component won't receive the router props (match, location, ...).
However we could do a little trick:
module UserPage = {
let component = ...;
let make = ...;
};
let userPageComponent =
UserPage.(
ReasonReact.wrapReasonForJs(~component, jsProps =>
make(~match=jsProps##_match, ~location=jsProps##location, [||])
)
);
<Route component=userPageComponent />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emmenko The wrapReasonForJs
returns a type of ReactClass and the component
attributes of the router requires a ReactElement type. Should I use this method or transform another way ?
For the moment, I just fixed some comments you advised rebase on master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right. Actually I think it's easier to use ReactClass
(I also use it in one of my projects).
~component: option(ReasonReact.reactClass)=?,
@bassjacob I have added some components