Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React Native Decorator Only Called Once

$
0
0

I'm trying out decorator for React Native but having a problem right now. The decorator function is only called once. If I assign something on the class property, the decorator doesn't get called. It works on Typescript Playground though. Here's my sample code: Sample Code Link To Typescript Playground

class VM {  @ReactiveState()  count = 1;}function ReactiveState() {  return function(target: any, key: string | symbol) {    let val = target[key];    const getter = () =>  {        return val;    };    const setter = (next: number) => {        console.log('updating flavor...');        val = `🍦 ${next} 🍦`;    };    Object.defineProperty(target, key, {      get: getter,      set: setter,      enumerable: true,      configurable: true,    });    console.log({val})  }}const vm = new VM();vm.count = 5;console.log({count: vm.count })// Result in React Native Metro Bundler Terminal: // { "count": 5 }// Result in Typescript Playground// { "count": "🍦 5 🍦" }vm.count = 6;console.log({count: vm.count })// Result in React Native Metro Bundler Terminal: // { "count": 6 }// Result in Typescript Playground// { "count": "🍦 6 🍦" }

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>