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 ...plugin,
181 id,
182 }
183 }) || []
184
185 // If nothing was open, seed from plugins with defaultOpen: true, or activate
186 // a lone plugin automatically.
187 let layout = existingState?.layout ?? null
188
189 const shouldFillWithDefaultOpenPlugins =
190 flattenTabs(layout).length === 0 && pluginsWithIds.length > 0
191 if (shouldFillWithDefaultOpenPlugins) {
192 layout = singleGroup(getDefaultActivePlugins(pluginsWithIds))
193 }
194
195 const state: DevtoolsStore = {
196 ...initialState,
197 plugins: pluginsWithIds,
198 state: {
199 ...initialState.state,
200 ...existingState,
201 layout,
202 },
203 settings: {
204 ...initialState.settings,
205 ...config,
206 ...settings,
207 },
208 }
209 return state
210}
211
212export type TanStackDevtoolsConfig = DevtoolsStore['settings']
213
214export const DevtoolsProvider = (props: ContextProps) => {
215 const [store, setStore] = createStore(
216 getExistingStateFromStorage(props.config, props.plugins),
217 )
218
219 setStorageItem(TANSTACK_DEVTOOLS_STATE, JSON.stringify(store.state))
220
221 // Provide a way for the core to update plugins reactively
222 const updatePlugins = (newPlugins: Array<TanStackDevtoolsPlugin>) => {
223 const pluginsWithIds = newPlugins.map((plugin, i) => {
224 const id = generatePluginId(plugin, i)
225 return {
226 ...plugin,
227 id,
228 }
229 })
230
231 setStore('plugins', pluginsWithIds)
232 }
233

Callers

nothing calls this directly

Calls 2

setStorageItemFunction · 0.90

Tested by

no test coverage detected