Hi All,
I’m using Object Module from rescript-core dependency. Not using Js.Dict.
let (personName, setPersonName) = React.useState(_ => {Object.empty()})
let nameKey = “name”
personName[nameKey]
At the moment, if I do that, the compiler assumes I’m attempting to access an array and prompts me for an array<'a>.
Getting error as,
This has type: {…“data”: Arr.t}
Somewhere wanted: array<'a>
You will not be able to do it with that syntax. For dynamic access of object fields, you will need to use the get or set function of rescript-core. E.g.,
let o = Object.empty()
let key = "yo"
Object.set(o, key, 1)->ignore
Object.get(o, key)->Console.log->ignore
// o[key] <- ERROR!