A simpler cleaner way to update a nested state object in a reducer?

reasonreact

#1

Hi there!

I currently use something like this to change the value for a field in a nested state object:

let reducer = (action, state) =>
  switch (action) {
  | Records.ChangeSearch(text) =>
    R.Update({
      ...state,
      recordsState: {
        ...state.recordsState,
        searchQuery: text,
      },
    })
  | ...

This seems like a lot of “boilerplate” (this pattern occurs very often in my reducer functions), so I was wondering if there is a simpler/shorter way to do this in ReasonML?

Update:

I think this syntax would be nice:

R.Update({...state, recordsState.searchQuery: text})

Any love for something like this? :slight_smile: