SolidJSS
SolidJSโ€ข3y agoโ€ข
18 replies
D0Z

updating nested object not triggering update

Heya I'm fairly new to SolidJS (You might have already seen some of my previous post of me strugglin' :D)
I'm trying to update the state of a nested object in a store but it doesn't seem to trigger an update on my component.

here is the method I use to update (it's declared in a context provider)

I'm not sure if I'm using produce well

const setOneFeature: ContextState[1]['setOneFeature'] = async (feature) => {
    const layerIndex = state.layers.findIndex(
      (item) => item && item.id === feature.layer
    )
    if (layerIndex === -1) {
      throw new Error('layer is undefined ๐Ÿ’ฉ')
    }
    setState(
      'layers',
      layerIndex,
      'features',
      produce((features) => {
        if (!features) {
          features = [feature]
        } else {
          const prevFeature = features.find((item) => item.id === feature.id)
          if (prevFeature) {
            _.merge(prevFeature, feature)
          } else {
            features.push(feature)
          }
        }
      })
    )
  }
Was this page helpful?