How to assign a optional value to optional labeled parameter in react?

As the title, i want to assign the fontFamily with a optional value. But the parameter fontFamily only accept string type. I can write it like that.

@react.component
let make = () => {
  let fontFamily = Some(`arial`)
  // let rounded = Some(true)
  switch fontFamily {
  | None => <div style={ReactDOMStyle.make()} />
  | Some(fontFamily) => <div style={ReactDOMStyle.make(~fontFamily, ())} />
  }
}

But if i have more optional variables that control the style, there will be much switch case and redundant code, how should i write it with a simple way?

@react.component
let make = () => {
  let fontFamily = Some(`arial`)
  // let rounded = Some(true)
  <div style={ReactDOMStyle.make(~fontFamily?, ())} />
}

@DZakh Thanks, But how to write it if i need to do a inlined map to a optional variable?
image

The question mark should be after the equal sign

1 Like

Thank you, it works.

Also there’s a good helper that will help avoiding None => None

2 Likes