|
| 1 | +--- |
| 2 | +title: Configuration |
| 3 | +id: configuration |
| 4 | +--- |
| 5 | + |
| 6 | +Both TanStack `DevTools` and `EventClient` can be configured. |
| 7 | + |
| 8 | +> **important** all configuration is optional unless marked (required) |
| 9 | +
|
| 10 | +## Devtools Configuration |
| 11 | + |
| 12 | +With the `Devtools` there are two configuration objects, regardless of Frameworks these are the same and are provided to the Devtools through props. |
| 13 | + |
| 14 | +- `config` configuration for the devtool panel and interaction with it |
| 15 | +- `eventBusConfig` configuration for the event bus |
| 16 | + |
| 17 | +The `config` object is mainly focused around user interaction with the devtools panel and accepts the following properties: |
| 18 | + |
| 19 | +- `defaultOpen` - If the devtools are open by default |
| 20 | + |
| 21 | +```ts |
| 22 | +{defaultOpen: boolean} |
| 23 | +``` |
| 24 | + |
| 25 | +- `hideUntilHover` - Hides the TanStack devtools trigger until hovered |
| 26 | + |
| 27 | +```ts |
| 28 | +{hideUntilHover: boolean} |
| 29 | +``` |
| 30 | + |
| 31 | +- `position` - The position of the TanStack devtools trigger |
| 32 | + |
| 33 | +```ts |
| 34 | +{position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'middle-left' | 'middle-right'} |
| 35 | +``` |
| 36 | + |
| 37 | +- `panelLocation` - The location of the devtools panel |
| 38 | + |
| 39 | +```ts |
| 40 | +{panelLocation: 'top' | 'bottom'} |
| 41 | + |
| 42 | +``` |
| 43 | + |
| 44 | +- `openHotkey` - The hotkey set to open the devtools |
| 45 | + |
| 46 | +```ts |
| 47 | +type ModifierKey = 'Alt' | 'Control' | 'Meta' | 'Shift'; |
| 48 | +type KeyboardKey = ModifierKey | (string & {}); |
| 49 | + |
| 50 | +{openHotkey: Array<KeyboardKey>} |
| 51 | +``` |
| 52 | + |
| 53 | +- `requireUrlFlag` - Requires a flag present in the url to enable devtools |
| 54 | + |
| 55 | +```ts |
| 56 | +{requireUrlFlag: boolean} |
| 57 | + |
| 58 | +``` |
| 59 | + |
| 60 | +- `urlFlag` - The required flag that must be present in the url to enable devtools. |
| 61 | + |
| 62 | +```ts |
| 63 | +{urlFlag: string} |
| 64 | +``` |
| 65 | + |
| 66 | +The `eventBusConfig` is configuration for the back bone of the devtools, the ``, and accepts the following properties: |
| 67 | + |
| 68 | +- `debug` - Enables debug mode for the EventBus |
| 69 | + |
| 70 | +```ts |
| 71 | +{debug: boolean} |
| 72 | +``` |
| 73 | + |
| 74 | +- `connectToServerBus` - Optional flag to indicate if the devtools server event bus is available to connect to |
| 75 | + |
| 76 | +```ts |
| 77 | +{connectToServerBus: boolean} |
| 78 | +``` |
| 79 | + |
| 80 | +- `port` - The port at which the client connects to the devtools server event bus |
| 81 | + |
| 82 | +```ts |
| 83 | +{port: number} |
| 84 | +``` |
| 85 | + |
| 86 | +Put together here is an example in react: |
| 87 | + |
| 88 | +```tsx |
| 89 | +import { StrictMode } from 'react' |
| 90 | +import { createRoot } from 'react-dom/client' |
| 91 | +import { FormDevtools } from '@tanstack/react-form' |
| 92 | + |
| 93 | +import { TanstackDevtools } from '@tanstack/react-devtools' |
| 94 | + |
| 95 | +import App from './App' |
| 96 | + |
| 97 | +createRoot(document.getElementById('root')!).render( |
| 98 | + <StrictMode> |
| 99 | + <App /> |
| 100 | + |
| 101 | + <TanstackDevtools |
| 102 | + config={{ hideUntilHover: true, }} |
| 103 | + eventBusConfig={{ debug: true }} |
| 104 | + plugins={[ |
| 105 | + { |
| 106 | + name: 'Tanstack Form', |
| 107 | + render: <FormDevtools />, |
| 108 | + }, |
| 109 | + ]} |
| 110 | + /> |
| 111 | + </StrictMode>, |
| 112 | +) |
| 113 | + |
| 114 | +``` |
| 115 | + |
| 116 | +## EventClient Configuration |
| 117 | + |
| 118 | +Configuration for the `EventClient` is as follows |
| 119 | + |
| 120 | +- `pluginId` (required) - The plugin identifier used by the event bus to direct events to listeners |
| 121 | + |
| 122 | +```ts |
| 123 | +{pluginId: string} |
| 124 | +``` |
| 125 | + |
| 126 | +- `debug` - Enables debug mode for the EventClient |
| 127 | + |
| 128 | +```ts |
| 129 | +{debug: boolean} |
| 130 | +``` |
| 131 | + |
| 132 | +Put together the `EventClient` configuration looks like: |
| 133 | + |
| 134 | +```tsx |
| 135 | +import { EventClient } from '@tanstack/devtools-event-client' |
| 136 | + |
| 137 | +type EventMap = { |
| 138 | + 'custom-devtools:custom-state': { state: string } |
| 139 | +} |
| 140 | + |
| 141 | +class customEventClient extends EventClient<EventMap> { |
| 142 | + constructor() { |
| 143 | + super({ |
| 144 | + debug: true, |
| 145 | + pluginId: 'custom-devtools', |
| 146 | + }) |
| 147 | + } |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +More information about EventClient configuration can be found in our [custom-plugins example](https://tanstack.com/devtools/latest/docs/framework/react/examples/basic) |
0 commit comments