Skip to content
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

Avoid curry for dispatch returned by useReducer #530

Closed
Austaras opened this issue Apr 21, 2020 · 4 comments · Fixed by #551
Closed

Avoid curry for dispatch returned by useReducer #530

Austaras opened this issue Apr 21, 2020 · 4 comments · Fixed by #551

Comments

@Austaras
Copy link

Austaras commented Apr 21, 2020

I have following code

[@react.component]
let make = () => {
  let (_, dispatch) = React.useReducer((state, _) => state + 1, 0);
  <button onClick={_e => dispatch(1)}> {ReasonReact.string("+")} </button>;
};

which compiles to

function App(Props) {
  var match = React.useReducer((function (state, param) {
          return state + 1 | 0;
        }), 0);
  var dispatch = match[1];
  return React.createElement("button", {
              onClick: (function (_e) {
                  return Curry._1(dispatch, 1);
                })
            }, "+");
}

Curry for dispatch is not needed, can this be fixed or it's limited by something else?

@Austaras
Copy link
Author

As my limited knowledge for bucklescript, maybe dispatch should be typed as ([@bs] 'action => unit)

@johnridesabike
Copy link
Contributor

This PR would address this issue #529

@Austaras
Copy link
Author

This PR would address this issue #529

cool, hope your pr will be merged soon

@johnridesabike
Copy link
Contributor

#529 got messed up. It was merged by accident, but none of its code was actually added to the master branch. #551 re-opened it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants