(selector: (state: AppState) => T)
| 127 | * ``` |
| 128 | */ |
| 129 | export function useAppState<T>(selector: (state: AppState) => T): T { |
| 130 | const store = useAppStore(); |
| 131 | |
| 132 | const get = () => { |
| 133 | const state = store.getState(); |
| 134 | const selected = selector(state); |
| 135 | |
| 136 | if (process.env.USER_TYPE === 'ant' && state === selected) { |
| 137 | throw new Error( |
| 138 | `Your selector in \`useAppState(${selector.toString()})\` returned the original state, which is not allowed. You must instead return a property for optimised rendering.`, |
| 139 | ); |
| 140 | } |
| 141 | |
| 142 | return selected; |
| 143 | }; |
| 144 | |
| 145 | return useSyncExternalStore(store.subscribe, get, get); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Get the setAppState updater without subscribing to any state. |
no test coverage detected