【发布时间】:2021-11-25 10:40:05
【问题描述】:
我已经在 React 类组件中这样做了,但是我需要在 React 函数组件中这样做,因为我想学习将类组件转换为函数组件。
onSortByPlatformAsc = () => {
var sortByPlatform = this.state.listGames.sort((a, b) =>
a.platform.localeCompare(b.platform)
);
this.setState({ listGames: sortByPlatform });
};
onSortByPlatformDesc = () => {
var sortByPlatform = this.state.listGames.sort((a, b) =>
a.platform.localeCompare(b.platform)
);
this.setState({ listGames: sortByPlatform.reverse() });
};
【问题讨论】:
标签: reactjs react-functional-component