avkonst/hookstate

Cannot convert null value to object

FranDepascuali opened this issue · 2 comments

Hi!
I'm a heavy user of this lib, so thank you very much :)

I've got one question, I'm receiving a crash inside hookstate.
I have a state that looks like this

interface StatsScreenState {
  ...
  searchStats: CollectionStats[] | null
  suggestionStats: CollectionStats[] | null
  ...
}

I set it this way

this.screenStatus$.searchStats.set(
      searchResults?.interestingResults || null,
    )
this.screenStatus$.suggestionStats.set(
      searchResults?.suggestedResults || null,
    )

Then I unwrap it this way on the component

  const {
    ...,
    searchStats,
    suggestionStats,
    ...
  } = useHookstate(viewModel.screenStatus$)

Like this it crashes.

If I change it to use noProxy, then it doesn't crash

  const {
    ...,
    searchStats,
    suggestionStats,
    ...
  } = useHookstate(viewModel.screenStatus$).get({ noproxy: true })

Seems to be related to nullable state

image

Note: It may be similar to this issue
#238

Does it crash if you replace variables assignment via destruction by assignment to a variable and individual properties access of it after?

Hi, I have attempted to write a reproducer and the tests passes fine with object destructure. It seem like you state value is null and you are attempting to get children nested states, which is invalid operation when the parent state value is null. Please reopen if you can provide more information.