Hi!
I am working with React and trying to build a common component that is used across the app, so some of the props need to be generic to adapt nicely to the different requirements. This is how I currently define it:
@react.component
let make = (
~data: array<'a>,
~yAxisKeys: array<string>,
...
) => {
...
}
Specifically, this component is a graph, that takes a set of data in the form of an array of objects. Each key in the object can be of type string or number. Then, it also takes a yAxisKeys prop, that determines which of the keys in the objects will be used for the y axis in the graph.
The main problem I am having is that at some point in the logic, I need to find the max value of these keys, for which I wanted to loop through them to find out the max value. My initial approach was getting the array of keys, and then using them to map the data
array and generate an array of the values, which I can then use to find the maximum with other logic (max is coming from lodash). This is how I did it for it with JS:
const keys = Object.keys(data[0]).filter(d => d !== xAxisKey)
const dataMaxValue = _.max(data.map(d => _.max(keys.map(k => Number(d[k]))))),
How would I translate this into ReScript? From my attempts, I am always running into a type issue for the last step d[k]
, since it doesn’t recognise that k can be a key of the data object.
Thanks!