MCPcopy Create free account
hub / github.com/TanStack/devtools / DevtoolsProvider

Function DevtoolsProvider

packages/devtools/src/context/devtools-context.tsx:182–230  ·  view source on GitHub ↗
(props: ContextProps)

Source from the content-addressed store, hash-verified

180 const settings = getSettings()
181
182 const pluginsWithIds =
183 plugins?.map((plugin, i) => {
184 const id = generatePluginId(plugin, i)
185 return {
186 ...plugin,
187 id,
188 }
189 }) || []
190
191 // If nothing was open, seed from plugins with defaultOpen: true, or activate
192 // a lone plugin automatically.
193 let layout = existingState?.layout ?? null
194
195 const shouldFillWithDefaultOpenPlugins =
196 flattenTabs(layout).length === 0 && pluginsWithIds.length > 0
197 if (shouldFillWithDefaultOpenPlugins) {
198 layout = singleGroup(getDefaultActivePlugins(pluginsWithIds))
199 }
200
201 const state: DevtoolsStore = {
202 ...initialState,
203 plugins: pluginsWithIds,
204 state: {
205 ...initialState.state,
206 ...existingState,
207 layout,
208 },
209 settings: {
210 ...initialState.settings,
211 ...config,
212 ...settings,
213 // Not in the settings tab, so the config wins over a stored value.
214 hideInAutomation:
215 config?.hideInAutomation ?? initialState.settings.hideInAutomation,
216 },
217 }
218 return state
219}
220
221export type TanStackDevtoolsConfig = DevtoolsStore['settings']
222
223const isRecord = (value: unknown): value is Record<string, unknown> =>
224 typeof value === 'object' && value !== null && !Array.isArray(value)
225
226export const DevtoolsProvider = (props: ContextProps) => {
227 // `config` and `plugins` are plain values here (initial settings; plugins
228 // update through `onSetPlugins`).
229 const initial = getExistingStateFromStorage(props.config, props.plugins)
230 const [store, setStore] = createStore(initial)
231
232 setStorageItem(TANSTACK_DEVTOOLS_STATE, JSON.stringify(initial.state))
233

Callers

nothing calls this directly

Calls 2

setStorageItemFunction · 0.90

Tested by

no test coverage detected