From 8e11605e827454c0b16fff322acac60a50b36678 Mon Sep 17 00:00:00 2001 From: Luis Herranz Date: Fri, 21 Oct 2022 11:50:20 +0200 Subject: [PATCH] Fix context not being updated on prop change --- src/runtime/components.js | 2 +- src/runtime/directives.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/runtime/components.js b/src/runtime/components.js index 8edcf5f4..acc75298 100644 --- a/src/runtime/components.js +++ b/src/runtime/components.js @@ -4,7 +4,7 @@ import { component } from './hooks'; export default () => { const WpContext = ({ children, data, context: { Provider } }) => { - const signals = useMemo(() => deepSignal(JSON.parse(data)), []); + const signals = useMemo(() => deepSignal(JSON.parse(data)), [data]); return {children}; }; component('wp-context', WpContext); diff --git a/src/runtime/directives.js b/src/runtime/directives.js index 5741046d..742b3260 100644 --- a/src/runtime/directives.js +++ b/src/runtime/directives.js @@ -17,11 +17,13 @@ export default () => { directive( 'context', ({ - directives: { context }, + directives: { + context: { default: context }, + }, props: { children }, context: { Provider }, }) => { - const signals = useMemo(() => deepSignal(context.default), []); + const signals = useMemo(() => deepSignal(context), [context]); return {children}; } );