Skip to content

Commit 7876801

Browse files
committed
feat: add Zustand store for selector-based config subscriptions
Adds Zustand-based config store to enable granular re-renders when config values change. Components can now use useConfigSelector() to subscribe to specific config properties instead of re-rendering on any config change. - Add zustand as dev and peer dependency - Create configStore.ts with useConfigSelector/useConfigValue hooks - Integrate Zustand store into ConfigProvider - Add legacy bridge (updateLegacyStore) for setConfig() compatibility - Support multiple WormholeConnect instances with isolated state - Add comprehensive tests for store and context integration
1 parent 376c4f4 commit 7876801

7 files changed

Lines changed: 1108 additions & 40 deletions

File tree

package-lock.json

Lines changed: 65 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@
188188
"vite-plugin-checker": "^0.10.3",
189189
"vite-plugin-dts": "^4.5.4",
190190
"vite-plugin-node-polyfills": "^0.24.0",
191-
"vitest": "^3.2.4"
191+
"vitest": "^3.2.4",
192+
"zustand": "^5.0.9"
192193
},
193194
"peerDependencies": {
194195
"@emotion/react": "^11.14.0",
@@ -200,7 +201,8 @@
200201
"@types/react": ">=18.0.0",
201202
"lucide-react": "^0.554.0",
202203
"react": ">=18.0.0",
203-
"react-dom": ">=18.0.0"
204+
"react-dom": ">=18.0.0",
205+
"zustand": "^5.0.0"
204206
},
205207
"peerDependenciesMeta": {
206208
"@types/react": {

src/config/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import RouteOperator from 'routes/operator';
2929
import { CHAIN_ORDER } from './constants';
3030
import { createUiConfig } from './ui';
3131
import { buildTokenCache } from './tokens';
32+
import { updateLegacyStore } from '../store/configStore';
3233

3334
export function buildConfig(
3435
customConfig: WormholeConnectConfig = {},
@@ -272,6 +273,11 @@ export function setConfig(customConfig: WormholeConnectConfig = {}) {
272273
/* @ts-ignore */
273274
config[key] = newConfig[key];
274275
}
276+
277+
// Sync to Zustand store for components using selector-based hooks
278+
// This updates the active ConfigProvider's store (if one is mounted)
279+
updateLegacyStore(config);
280+
275281
if (typeof window !== 'undefined') {
276282
/* @ts-ignore */
277283
window._connectConfig = config;

0 commit comments

Comments
 (0)