Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #90 from WordPress/fix-context-not-updated-on-prop…
Browse files Browse the repository at this point in the history
…-change

🎨 Fix context not updated on prop change
  • Loading branch information
luisherranz authored Oct 21, 2022
2 parents 647589d + 8e11605 commit 0f90f67
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/runtime/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Provider value={signals}>{children}</Provider>;
};
component('wp-context', WpContext);
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Provider value={signals}>{children}</Provider>;
}
);
Expand Down

0 comments on commit 0f90f67

Please sign in to comment.