Select to view content in your preferred language

Redux store and the Settings Component

334
0
06-13-2023 02:27 PM
ShaunLangley
Occasional Contributor

I've been trying for the last couple days to implement a redux store for my widget/application and I've observed a few things. 

I can successfully dispatch to and read from my redux store from within the runtime component of my widget, however when I try to do the exact same thing from inside my Settings component, I'm receiving 'state.myState' is undefined.

Has anyone been able to update their redux store from the Settings component of a widget?

 I've simplified my implementation example but I think this illustrates what I'm trying to accomplish

 

export default class Setting extends React.PureComponent<
AllWidgetSettingProps<IMConfig> & {
  category: string
}, {}
> {
  static mapExtraStateProps (state: IMState) {
    return {
      category: state.layerState.category
    }
  }

  onChange = (evt) => {
    this.props.dispatch({
      type: 'ADD_CATEGORY',
      val: evt.target.value
    })
  }

  render () {
    return (
        <div>
          <div className="widget-setting-layerListPlus">
            <SettingSection
                title="Data Category"
                role="group"
                aria-label="Data Category"
            >
              <SettingRow>
                <div className="category-input w-100 d-flex flex-column" >
                  <div className="category-input-item input">
                            <Input
                                id="category-input"
                                onChange={this.onChange}
                                value={this.props.category}
                            />
                  </div>
                </div>
                <div className="category-input-item button p-1">
                </div>
              </SettingRow>
            </SettingSection>
          </div>
        </div>
    )
  }
}

 

 

0 Kudos
0 Replies