As you can see, every icon’s make function will have the same props so I’d like to move the signature into a separate type. Following code gives me an error: This call is missing an argument of type (?size: option<int>)
I personally find this code way more complex than necessary though, I’d probably rather duplicate props for each component as you did in your original example.
Thank you, the problem with duplication would be if I’d introduce a new param for a prop. Plus there’s a lot of icons which I potentially could use in the project.
That seems like a lot of code, is there a way for code gen here?
You could write a small script that could code-gen the ReScript code you need as an Icons.res file? I guess this would be a one-time job to create this file anyways.
Quick sketch of what I mean:
// scripts/GenIcons.res
let icons = ["Minus", "Square", "X"] // you may get this data automatically from the module exports?
icons->Js.Array2.forEach(name => {
Js.log(`
module ${name} = {
@module("react-feather")
@react.component
let make: (~size: int=?) => React.element = "${name}"
}
`)
})
compile that and then run node scripts/GenIcons.mjs > src/components/Icons.res.