From a003f75fc1902d8006b80fb0e2ad48050aa511b0 Mon Sep 17 00:00:00 2001 From: Guy Carmeli Date: Wed, 21 Aug 2019 14:44:26 +0300 Subject: [PATCH] Remove Proxy from React.Context example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hermes doesn't support Proxy ¯\_(ツ)_/¯ --- playground/src/context/index.js | 21 ++++++++++----------- playground/src/screens/ContextScreen.js | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/playground/src/context/index.js b/playground/src/context/index.js index 8d58a922ffe..ae0650d3d71 100644 --- a/playground/src/context/index.js +++ b/playground/src/context/index.js @@ -1,21 +1,20 @@ const React = require('react'); -let ctx = { +const _context = { title: 'Title from global context', count: 0 }; - -const stateAwareContext = (component) => - new Proxy(ctx, { - set: function (obj, prop, value) { - obj[prop] = value; - component.setState({ context: stateAwareContext(component) }); - return true; - } - }); +const contextWrapper = (component) => ({ + ..._context, + incrementCount: () => { + _context.count++; + component.setState({ context: contextWrapper(component) }) + } +}); const GlobalContext = React.createContext({}); class ContextProvider extends React.Component { - state = {context :stateAwareContext(this)}; + state = { context: contextWrapper(this) } + render() { return ( diff --git a/playground/src/screens/ContextScreen.js b/playground/src/screens/ContextScreen.js index 3eb2e0fd729..c6c26641030 100644 --- a/playground/src/screens/ContextScreen.js +++ b/playground/src/screens/ContextScreen.js @@ -24,7 +24,7 @@ class ContextScreen extends React.Component { {ctx => Provider value: {ctx.title}} - {ctx =>