mobx-persist
mobx-persist copied to clipboard
MobX 6: Memory leak in hydrate()
I want to use hydrate()
many times with short live mobx-store objects. Therefor I want to clear any watchers. But there is a reaction into hydrate()
function and I can't call dispatch function of this reaction. hydrate source code:
// mobx-persist/src/index.ts
export function create({
storage = Storage as any,
jsonify = true,
debounce = 0
}: any = {}) {
return function hydrate<T extends Object>(key: string, store: T, initialState: any = {}, customArgs: any = {}): IHydrateResult<T> {
// ...
const result = hydration()
reaction(
() => serialize(schema, store),
(data: any) => storage.setItem(key, !jsonify ? data : JSON.stringify(data)),
{
delay: debounce
}
)
return result
In MobX@6 reaction function returns dispose function. MobX docs says Always dispose of reactions.
hi did you manage to get the persist work with mobx 6? @RusovVladimir