Select to view content in your preferred language

Experience Builder mapExtraStateProps usecase

844
2
02-01-2024 10:32 PM
BhaveshSuthar
Emerging Contributor

Hello everyone in the community!

So I am creating a custom widget using functional component and I need to use the mapExtraStateProps function in my component, I know that in class component I just need to define the function and is internally invoked. But how does this work in functional component?

Thanks for your help in advance.

0 Kudos
2 Replies
BhaveshSuthar
Emerging Contributor

I found in the documentation that we can use useSelect similar to useSelector in Redux. How to import useSelect?

0 Kudos
QunSun
by Esri Contributor
Esri Contributor

Hi @BhaveshSuthar , you just need to set Widget.mapExtraStateProps = function(state, props) {}. This is equivalent to class component.

Here is the code snippet.

 

/** @jsx jsx */
import { React, type AllWidgetProps, type IMState } from 'jimu-core'
import { type IMConfig } from '../config'

export interface ExtraCustomWidgetProps {
  ...
}

export interface WidgetProps extends AllWidgetProps<IMConfig>, ExtraCustomWidgetProps {
  ...
}

const Widget = (props: WidgetProps): React.ReactElement => {
  return (
    ...
  )
}

// define mapExtraStateProps for functional widget
Widget.mapExtraStateProps = (state: IMState, props: AllWidgetProps<IMConfig>): ExtraCustomWidgetProps => {
  return {
    ...
  }
}

export default Widget