Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getters in ES6 functional component React.js

I am using stateless component in React and I found issue with using Getters.

for the statefull component (class based component) it is properly working but how can I use this in stateless(functional component);

 // this is code for statefull component(class based component)

get lookupsOfSelectedGroup(){
        const lookUps = this.props.mainLookups.filter(
          item => item.extras.parent === this.state.activeGroup
        );

        if (lookUps[0] && lookUps[0].responseStatus === 200) {
          return lookUps[0].response.lookup;
        }

        return [];
  }


// this is the code for functional component I did:

    get lookupsOfSelectedGroup =()=> {
        const lookUps = this.props.mainLookups.filter(
          item => item.extras.parent === this.state.activeGroup
        );

        if (lookUps[0] && lookUps[0].responseStatus === 200) {
          return lookUps[0].response.lookup;
        }

        return [];
      }    ```

Cannot find name 'get'.
like image 651
kamran jan khalilz Avatar asked Dec 04 '25 08:12

kamran jan khalilz


1 Answers

You can only use the get and set keywords in ES6 classes and object literals.

Check the reference.

like image 114
Clarity Avatar answered Dec 06 '25 21:12

Clarity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!