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

Bug: Not possible to use default value for renamed props in JSX 4 #6375

Closed
DZakh opened this issue Aug 29, 2023 · 4 comments · Fixed by #6377
Closed

Bug: Not possible to use default value for renamed props in JSX 4 #6375

DZakh opened this issue Aug 29, 2023 · 4 comments · Fixed by #6377

Comments

@mununki
Copy link
Member

mununki commented Aug 29, 2023

Good catch!

module C3 = {
  type props<'disabled> = {disabled?: 'disabled}

  let make = ({disabled: ?everythingDisabled, _}: props<bool>) => {
    let disabled = switch disabled { // should use everythingDisabled
    | Some(disabled) => disabled
    | None => false
    }

    {
      React.string(everythingDisabled ? "true" : "false")
    }
  }
  ...
}

@mununki
Copy link
Member

mununki commented Aug 29, 2023

This seems fine to me. I think this could be fixed at the same time with issue #6374.
What do you think?

module C3 = {
  type props<'disabled> = {disabled?: 'disabled}

  let make = ({disabled: ?everythingDisabled_, _}: props<bool>) => { // rename alias *_
    let everythingDisabled = switch everythingDisabled_ { // refer to it here
    | Some(everythingDisabled) => everythingDisabled
    | None => false
    }

    {
      React.string(everythingDisabled ? "true" : "false")
    }
  }
  ...
}

@mununki
Copy link
Member

mununki commented Aug 29, 2023

As you suggested:

module C3 = {
  type props<'disabled> = {disabled?: 'disabled}

  let make = (props: props<bool>) => {
    let everythingDisabled = switch props {
    | {disabled} => disabled
    | _ => false
    }

    {
      React.string(everythingDisabled ? "true" : "false")
    }
  }
  ...
}

What do you think?

@mununki
Copy link
Member

mununki commented Aug 29, 2023

Ah, I'm afraid of the case when we have other props along with disabled. Destructuring would be better for that case.

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