( storeKey_: S, selector: StateSelector<Parameters<S>[0], U>, selectorName: string, equalityFn: (oldSlice: U, newSlice: U) => boolean = shallowEqual, storeContext: React.Context<UtopiaStoreAPI | null> = EditorStateContext, )
| 130 | * It is a good practice to use object destructure to consume the return value. |
| 131 | */ |
| 132 | export const useEditorState = <K extends StoreKey, S extends (typeof Substores)[K], U>( |
| 133 | storeKey_: S, |
| 134 | selector: StateSelector<Parameters<S>[0], U>, |
| 135 | selectorName: string, |
| 136 | equalityFn: (oldSlice: U, newSlice: U) => boolean = shallowEqual, |
| 137 | storeContext: React.Context<UtopiaStoreAPI | null> = EditorStateContext, |
| 138 | ): U => { |
| 139 | const storeKey: K = storeKey_.name as K |
| 140 | const context = React.useContext(storeContext) |
| 141 | |
| 142 | const wrappedSelector = useWrapSelectorInPerformanceMeasureBlock(storeKey, selector, selectorName) |
| 143 | |
| 144 | if (context == null) { |
| 145 | throw new Error('useStore is missing from editor context') |
| 146 | } |
| 147 | return context.stores[storeKey](wrappedSelector, equalityFn as EqualityChecker<U>) |
| 148 | } |
| 149 | |
| 150 | export const useSelectorWithCallback = <K extends StoreKey, S extends (typeof Substores)[K], U>( |
| 151 | storeKey_: S, |
no test coverage detected