2

i'm using Proxy for my react native app

import Setting from "./Setting";
const lang = { ar : {...} , en : {...} , fr : {...} };

export const string = new Proxy(lang, {get: function (object, name){return object[Setting.settings.lang][name]}});
export default string;

but throws cannot find variable Proxy

Ali Faris
  • 17,754
  • 10
  • 45
  • 70

2 Answers2

4

I can't add a comment, but i think your question is linked to the same question:- Proxy ES6

In otherwords, you'll need to import a polyfill.

--

Edited to add the codes:

import 'proxy-polyfill';
.
.
_samplePolyfill = () => {
  function observe(o, callback) {
    return new Proxy(o, {
      set(target, property, value) {
        callback(property, value);
        target[property] = value;
      },
    });
  }

  const x = {'name': 'BB-8'};
  const p = observe(x, (property, value) => console.warn(property, value));
  p.name = 'BB-9';
}
.
.
componentDidMount() {
  this._samplePolyfill();
}
Han
  • 728
  • 5
  • 17
  • 1
    Updated, the import needs to be some sort of name that is not Proxy. It's found that you need the old version, you can find the problem about it online. So run npm with: `npm install proxy-polyfill@v0.1.6` Hope this helps. – Han Nov 29 '17 at 15:41
0

For a weird reason if you enable RemoteJs Debugger it works

Ctrl/CMD + M

if you had issue connecting to remote debugger follow this : Unable to connect with remote debugger

Abd Rmdn
  • 480
  • 4
  • 11
  • When you enable the debugger, your JS is run on chrome (that's why it's “remote"). Your chrome has the Proxy object. The mobile JS engine, which is used by react native on device, does not. – Yairopro Jul 29 '19 at 13:59