我在 React 中使用无状态组件,我发现使用 Getters 有问题。
对于有状态组件(基于类的组件),它可以正常工作,但是如何在无状态(功能组件)中使用它;
// 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'.
慕村9548890
蛊毒传说
相关分类