MCPcopy
hub / github.com/concrete-utopia/utopia / useEditorState

Function useEditorState

editor/src/components/editor/store/store-hook.ts:132–148  ·  view source on GitHub ↗
(
  storeKey_: S,
  selector: StateSelector<Parameters<S>[0], U>,
  selectorName: string,
  equalityFn: (oldSlice: U, newSlice: U) => boolean = shallowEqual,
  storeContext: React.Context<UtopiaStoreAPI | null> = EditorStateContext,
)

Source from the content-addressed store, hash-verified

130 * It is a good practice to use object destructure to consume the return value.
131 */
132export 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
150export const useSelectorWithCallback = <K extends StoreKey, S extends (typeof Substores)[K], U>(
151 storeKey_: S,

Callers 15

useIconColorFunction · 0.90
css-vars.tsxFile · 0.90
UserConfigurationFunction · 0.90
user-bar.tsxFile · 0.90
useGridPanelStateFunction · 0.90
useVisibleGridPanelsFunction · 0.90

Tested by

no test coverage detected