diff --git a/docs/guides/typescript.md b/docs/guides/typescript.md index 1f9432f4b1..f52708eccb 100644 --- a/docs/guides/typescript.md +++ b/docs/guides/typescript.md @@ -259,7 +259,11 @@ const loggerImpl: LoggerImpl = (f, name) => (set, get, store) => { set(...a) console.log(...(name ? [`${name}:`] : []), get()) } - store.setState = loggedSet + const setState = store.setState + store.setState = (...a) => { + setState(...a) + console.log(...(name ? [`${name}:`] : []), store.getState()) + } return f(loggedSet, get, store) } diff --git a/readme.md b/readme.md index fd94573108..3ee0ee3558 100644 --- a/readme.md +++ b/readme.md @@ -284,31 +284,6 @@ clearForest() [Alternatively, there are some other solutions.](./docs/guides/updating-state.md#with-immer) -## Middleware - -You can functionally compose your store any way you like. - -```jsx -// Log every time state is changed -const log = (config) => (set, get, api) => - config( - (...args) => { - console.log(' applying', args) - set(...args) - console.log(' new state', get()) - }, - get, - api, - ) - -const useBeeStore = create( - log((set) => ({ - bees: false, - setBees: (input) => set({ bees: input }), - })), -) -``` - ## Persist middleware You can persist your store's data using any kind of storage.